Releases: christianalfoni/flux-angular
Modernized build, add flux.listenTo
The listenTo
callback is now accessible off the flux
object for use outside the angular lifecycle (e.g. React). It returns an unsubscribe callback that can be invoked upon cleanup of the component.
Updated the package to use rollup so it is compatible as an ES6 import, UMD module, or common module. Only breaks backward compatibility with 3.x if code was explicitly referencing release/flux-angular.js instead of importing the normal way.
Webpack compatibility
flux-angular can now successfully be installed and required with npm and webpack.
Compatibility with IE11 and Safari
Fixes an issue where some operators in the immutable state tree used functions not present in IE11 and Safari.
Make it easier to test stores
During testing $listenTo
callbacks are not wrapped in an $evalAsync
call which means testing the interaction between a store and a controller requires less overhead.
Ensure state is initialized when angular loads
Fixes a bug where state could be undefined while angular was running its initial digest cycle and initializing controllers.
Fix memory leak in Baobab
Upgrades to the latest Baobab which fixes a memory leak that could surface if initialize
was called multiple times for the same store.
Better integration with angular
Baobab by default batches up the notifications about changes to the immutable stores into the next tick to improve performance. However, since the next tick is outside the angular digest cycle this led to cases where the emit was not caught by angular. Now all $listenTo
callbacks are wrapped in $evalAsync
by default to ensure angular is alerted of the Baobab changes. For most users this should just make things more reliable, but users will still want to test that there are no adverse effects. The old behavior can be re-enabled by setting fluxProvider.useEvalAsync(false);
Upgrade dependencies
Upgraded Baobab to 2.3.2
Upgraded Angular to allow for 1.5.x
Version 3.0.0
Breaking changes
This switches from the deprecated immutable-store to using Baobab to
store immutable state. Because the API for Baobab is
different there are breaking changes in how state is manipulated, but
there is also one big benefit: no need to call emitChange()
when state
is updated because freezer has an event API that notifies when any state
changes.
The README was also updated and re-arranged to try and group related
concepts together.
BREAKING CHANGES:
- Immutable state must be created in the
initialize
method of a store
usingthis.immutable()
- State must be fetched using
state.get()
- State must be updated using the Baobab API
- Event wildcards have been replaced with listening to a specific path
on the state tree
An example of a version 2 immutable store:
angular.module('app', ['flux'])
.store('MyStore', function (flux) {
var state = flux.immutable({ items: [] });
return {
handlers: {
'addItem': 'addItem'
},
addItem: function (item) {
state = state.person.push(item);
this.emitChange();
},
exports: {
get items() {
return state.items;
}
}
};
});
would now be:
angular.module('app', ['flux'])
.store('MyStore', function (flux) {
return {
initialize: {
this.state = this.immutable({ items: [] });
}
handlers: {
'addItem': 'addItem'
},
addItem: function (item) {
this.state.push('items', item);
},
exports: {
get items() {
return this.state.get('items');
}
}
};
});
Other updates
- dispatchr was updated to the latest version
- codebase converted to es6
Version 2.6.0
- Actual event triggered available on
this.dispatcherEvent
. Useful when using asterix events - Removed pre-injection. Giving warnings on possible missing injections instead. Pre-injection has scenarios where it causes problems. It is better for the developer to choose when stores should be injected. Even if you just inject all of them in the
run
- Project now exports "flux", so you can require it directly in you angular dependency array