Closed danfma closed 7 years ago
Transactions?
Hi, disablin state updates temporarily would be tge start of a bunch of 'why is my app not updating' problems.
If you need to make a bunch of updates that may affect to your app performance use transactions (there should be a really big number of updates to see a performance penalty) as @kuraga recommended.
For async operations just update the state when the call finish:
var f = new Freezer({
loading: false,
whatever: '',
other: ''
});
f.on('startAsync', () => {
// We set up a flag to show some loading message
// in our app
f.get().set({loading: true});
asyncCall( () => {
// Here you will update the state
// f.get().set({whatever, 'yeah'});
f.get().set({loading: false});
// If you need to update more than one
// domain of your state you can trigger a new
// event
f.trigger('endAsync', 'yeah');
});
});
// This handles whatever
f.on('endAssign', result => {
f.get().set({whatever: result});
});
// This handles other
f.on('endAssign', result => {
f.get().set({other: 'Other ' + result});
});
Hey,
It would be good in some scenarios, like async calls, that we could control when the state should update manually (disabling the auto sync on next tick).