A Flight mixin for exposing component state via an observable stream.
npm install flight-with-observable-state
A Flight mixin which extends the flight-with-state mixin by exposing the component's state as an observable stream.
``bash`
npm install --save flight-with-observable-state
This module requires flightjs, rx and flight-with-state as a peer dependencies.
Here's an example component that uses withObservableState.
`jswithObservableState
var ToggleButton = flight.component(
// Use before your component definition.
withObservableState,
function toggleButton() {
this.attributes({
initiallyActive: false
});
// Define an instance's initialState
this.initialState({
active: false
});
this.after('initialize', function () {
this.on('click', this.toggle);
// Subscribe to a stream of the changing state
this.observableState.subscribe(this.update.bind(this));
// Transition the state using replaceState
this.replaceState({
active: this.attr.initiallyActive
});
});
this.toggle = function () {
// Merge changes onto the state using mergeStatethis.state
this.mergeState({
// Access the current state using
active: !this.state.active
});
};
this.update = function (state) {
this.$node.toggleClass('is-active', state.active);
};
}
);
`
withObservableState includes the flight-with-state mixin, and as such provides all of those methods as part of its API. You do not need to include withState in your own component. withObservableState also introduces the observableState property.
observableState property provides an observable stream of the component's changing state. In actuality it is an instance of a RXJS Observable connected to a RXJS BehaviourSubject.
To develop this module, clone the repository and run:
```
$ npm install && npm test
If the tests pass, you have a working environment. You shouldn't need any external dependencies.
Anyone and everyone is welcome to contribute. Please take a moment to
review the guidelines for contributing.