mxriverlynn / backbone.memento

store and restore your model's state
367 stars 51 forks source link

implementing clear and fixing variable scoping #3

Closed jondot closed 13 years ago

jondot commented 13 years ago

Hi Derick, I've implemented clear, actually started by calling it 'reset' because i needed it, but then saw that the model already contained such a thing and it was not implemented.

some more notes about code in commit body: https://github.com/jondot/backbone.memento/commit/4537b9fa0972ceff73e49a65ad5cbfa8dc9fbf3a

Hope this helps!

mxriverlynn commented 13 years ago

wow! i have no idea how that one slipped through and still worked! thanks for noticing / fixing that, and for the "reset" function! i had though about something similar a while ago but had not yet needed it.

merged and released as v0.1.2

jondot commented 13 years ago

Sure, my pleasure.

Please notice though, that I've recognized some perhaps mental mismatch in the way a developer might use a memento. If I instantiate a memento, and run a restore or clear - the behavior is somewhat undefined. A memento doesn't have an initial state or base condition referred to as 'initial model state'.

However, if we instantiate a memento, and by fact of instantiation, the memento 'captures' initial model state automatically as slot [0], you have a base condition that is always valid (and is not clear-able). It may serve better in terms of 'pitfall of success'.

The way to do it in the current toolset, is to push a first 'save point' into a memento right after initializing. It is more flexible, but it may be needed to be emphasized in docs or such.

I am undecided on which of the two is more 'correct' but it's a nice mental problem that i've stumbled upon and wanted to share.

mxriverlynn commented 13 years ago

i've done things like that in the past, too... i'm 50/50 on it at this point. the times i don't have a "baseline", i want it. the times i do, it drives me nuts. it might be nice to support this feature if/when people want it... to mark a given state as "permanent" or something like that... maybe even a named state that is always available, even if you reset / clear everything else out... but i'd like to wait until we see that need before we build it.

jondot commented 13 years ago

yup!