Changelog
0.16.4
Changelog
0.16.1
This release is a pretty big one and it also marks Alt's first breaking changes.
Upgrade guide is included with each bullet point.
New method signatures for createStore, createActions, etc. commit
Upgrade Guide
// old behavior
class MyStore {
constructor(alt) { }
}
// allows you to pass in your own arguments to the constructors
class MyStore {
constructor(alt, one, two, three) { }
}
alt.createStore(MyStore, null, alt, 1, 2, 3)
beforeEach/afterEach methods have been moved to lifecycle. commit
Upgrade Guide
// the new way
class Store {
constructor() {
this.on('beforeEach', () => {
});
}
}
withAltContext is now in decorator form. commit
Upgrade Guide
As a decorator:
@withAltContext(alt)
export default class App extends React.Component {
render() {
return <div>{this.context.flux}</div>
}
}
As a function:
export default withAltContext(alt)(App);
Lifecycle method serialize and deserialize have been renamed and moved. commit
Upgrade Guide
// new hotness
class TodoStore {
static config = {
onSerialize() {
},
onDeserialize() {
}
}
}
atomicTransactions util has been renamed to just atomic. commit
Upgrade Guide
alt/util/atomicTransactions
to alt/util/atomic
Removed mixins
from browser-with-addons. commit
Mixins are dead, all hail our new higher-order component overlords. Please use AltContainer instead: http://alt.js.org/docs/components/altContainer/
Method signature for beforeEach, afterEach, error lifecycle events have changed. commit
Upgrade Guide
fn(actionName, data, state)
.fn(payload, state)
where payload
is an object.action
and data
which contain the information from before.class Store {
constructor() {
this.on('beforeEach', (payload, state) => {
console.log(payload.data);
});
}
}
@timetravel
class TodoStore { }
TodoStore.undo(3);
TodoStore.redo(1);
@connectToStores
class TodoApp extends React.Component {
static getStores() {
return [TodoStoreStore]
}
static getPropsFromStores(props) {
return TodoStore.getState()
}
render() {
return (
<div>
{this.props.todos.map(todo => <Todo todo={todo} />}
</div>
)
}
}
@immutable
class TodoStore {
constructor() {
this.state = Immutable.Map({})
}
}
alt.takeSnapshot(TodoStore); // returns only TodoStore's snapshot
alt.recycle(TodoStore); // recycles only TodoStore
import { createStore } from 'alt/utils/decorators'
@createStore(alt)
export default class TodoStore {
constructor() {
}
}
alt.stateTransforms.push(Store => {
// make every store atomic
return atomic(alt)(Store)
})
class TodoStore {
static config = {
getState(state) {
// adds a new todo every time you getState
return states.todos.push({ 'Another todo!' });
}
}
}
class FooActions {
constructor() {
this.myAction = function (x) {
this.dispatch(x);
};
}
}
// inject lets you inject arbitrary props to your children
<AltContainer inject={{ foo: 7, bar: 'hello' }}>
<div />
</AltContainer>
// div gets prop foo=7 and bar='hello'
component
prop to AltContainer. commit
alt has a prepare
method which prepares a payload for bootstrapping. commit
// rather than rendering its children you can now pass in a component
<AltContainer component={MyComponent} />
// equivalent to
<AltContainer>
<MyComponent />
</AltContainer>
// if you yearn for a react-like API you can now has
const alt = new Alt({ stateKey: 'state' });
class Store {
constructor() {
this.state = {
stateGoesHere: 1,
yay: 2
};
this.nowItsPrivate = true;
}
}
// Customize the way getState and setState behave at the app level.
const alt = new Alt({
getState(state) {
// add fuzzlewuzzle to every state
state.fuzzlewuzzle = true;
return state;
},
setState(existingState, newState) {
// forget existingState, in with the new out with the old
return newState;
}
});
maxEvents
parameter to DispatcherRecorder. This allows you to specify how many events you wish to record. commitdisplayName
. commit