SteveSanderson/knockout — Issue #181: Add the concept of observable states
Author: rosenfeld
Created: 2011-10-20 19:28:44+00:00
State: open

While editing data, it is a common request that we should be able to apply the changes or rollback. It is so common that Knockout should help developers here.

An alternative to this problem would be introducing the concept of states. So, an observable could have states. Or we could introduce some ko.statefulObserver()...

When the object changes its state, all current properties could be copied over a new object mapped by the state. For instance, consider that we would have some internal value map:

value['normal'] = {} // all properties would be added to this object

Then, when a user changes a state:

myObservable.changeState('editing')

Then, all values['normal'] would be copied over values['editing'] and all changes would be reflected only on this state.

Templates should be bound to some state. That way, an editing templating would be bound to the 'editing' state and it would respond to changes only on this state while other templates would be affected only by the 'normal' state...

On myObservable.applyState('editing') (equivalent to applyState('editing', 'normal')), those changes would then be copied back to the normal state and reflected on usual templates...

Feel free to ask me any questions if this explanation is not clear enough...