An ultra-lightweight Flux-like architecture for HTML5 apps using Facebook's React library.
npm install --save exim
If you're using Bower: bower install exim
Because, we hate complexity. Redux is very complex. Adding Redux to your app won't solve any problem per se — you would need to add tons of Redux plugins.
Exim focuses on three things:
- Simple actions with unidirectional flow. You cannot change app data from the outside.
- Easy lifecycle management and optimistic updates. Those are solid requirements for many modern apps.
- Being a first-class React citizen. Subscribing to data updates or calling an action should never be complex.
var User = Exim.createStore({
fetch: {
on(name) {
return request.get('/v1/user/' + name);
},
did(response) {
this.set({currentUser: response});
},
while(isFetching) {
// This allows us to show a spinner.
this.set({isFetching: isFetching});
}
},
create: {
on(data) {
return request.put('/v1/user', data);
},
did(userInfo) {
const list = this.get('users');
list.push(userInfo);
this.set({users: list}); // Immutable by default. Need to write updates explicitly.
},
didNot(error) {
// Revert your optimistic updates here.
console.error('Whoops. Something happened. You can revert some state here. Code:', error);
}
}
});
// In your view
React.createClass({
mixins: [User.connect('isFetching')],
create() {
User.actions.create({name: 'Jonny Bravo'});
},
render() {
if (this.isFetching) {
return <div>Showing a spinner is as simple as that.</div>
} else {
return <div onClick={this.create}>Let me create something!</div>
}
}
});
The only hard dependency is React.js.
- Switched to ES6 modules.
- Stores can now use
propTypes
to specify the exact data types of properties. - Massively improved debugging.
- Add React Router 1.0 support.
- Store's
path
argument is optional.
- Fix temporary variables for
will
cycle.
while
andon
/did
are now wrapped in transactions — every dataset
would be groupped and then executed as one command instead of a fewset
s.- You can now use
class
as an alias to react'sclassName
for HTML tags. cx
helper enhancements.- Performance improvement.
- Test release using Freezer.js for immutability.
- Fix action's chain bug.
- Implement store.reset() / store.reset(prop).
- Getter: Revert logic. Fix allowed methods bug.
- while[Action]: Fix
didNot
case bug. - Fix Unhandled rejection error.
- Massive reduce in size. Exim is only 4K now (when gzipped).
- Dropped all dependencies. But of course you'll need to include React.
- Massive simplification.
- Rewritten in ES6.
- Implement Exim.createView.
- Exim.Router enhancements.
- Add Exim.helpers.
- Initial release.
Exim is currently maintained by Paul Miller and Artem Yavorsky.
The MIT License (MIT)
Copyright (c) 2014 Hellyeah LLC http://hellyeah.is
With contributions by several individuals: https://github.com/hy-dev/exim/graphs/contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.