Skip to content

Commit

Permalink
Merge pull request #246 from flightjs/mixin_doc
Browse files Browse the repository at this point in the history
Doucment Component.mixin
  • Loading branch information
angus-c committed Apr 19, 2014
2 parents 6b7b9cb + 4198344 commit 5da831b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions doc/mixin_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,39 @@ 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 (`components/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() {
//..
}
});
```


0 comments on commit 5da831b

Please sign in to comment.