From 2518bba73c9902e0cd6fa1b13bcb8982a6af4485 Mon Sep 17 00:00:00 2001 From: angus croll Date: Fri, 18 Apr 2014 17:58:33 -0700 Subject: [PATCH 1/2] added Component.mixin doc --- doc/mixin_api.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/doc/mixin_api.md b/doc/mixin_api.md index 8503ca9a..6edfb83b 100644 --- a/doc/mixin_api.md +++ b/doc/mixin_api.md @@ -95,3 +95,41 @@ define(function(require) { }); ``` + +## Creating a new Component from an existing one + +Existing Components can act as base components from which additional Components can +be made. + +For example, let's say all your components need to iplement some touch screen behavior and also +override Flight's default `trigger` function. Instead of having to add these mixins to every component, +you can use them to create a base component (`Base`) which all other components will extend. + +```js +define(function(require) { + var defineComponent = require('flight/lib/component'); + var withTouchScreen = require('mixins/with_touchscreen'); + var withCustomTrigger = require('mixins/with_custom_trigger'); + + return defineComponent(withTouchScreen, withCustomTrigger); +}); + +``` + +Component constructors have a `mixin` method which can be used to create a new Component constructor +based on the original: + +```js +define(function(require) { + var Base = require('components/base'); + + return Base.mixin(shoppingCart); + + function shoppingCart() { + //.. + } +}); + +``` + + From 419834425a56be9df5b7adbbc2d4f8d4a0517e5e Mon Sep 17 00:00:00 2001 From: angus croll Date: Fri, 18 Apr 2014 18:01:01 -0700 Subject: [PATCH 2/2] Update mixin_api.md --- doc/mixin_api.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/mixin_api.md b/doc/mixin_api.md index 6edfb83b..853533a0 100644 --- a/doc/mixin_api.md +++ b/doc/mixin_api.md @@ -103,7 +103,7 @@ be made. For example, let's say all your components need to iplement some touch screen behavior and also override Flight's default `trigger` function. Instead of having to add these mixins to every component, -you can use them to create a base component (`Base`) which all other components will extend. +you can use them to create a base component (`components/base`) which all other components will extend. ```js define(function(require) { @@ -113,7 +113,6 @@ define(function(require) { return defineComponent(withTouchScreen, withCustomTrigger); }); - ``` Component constructors have a `mixin` method which can be used to create a new Component constructor @@ -129,7 +128,6 @@ define(function(require) { //.. } }); - ```