hay / stapes

the Javascript MVC microframework that does just enough
http://hay.github.io/stapes
MIT License
443 stars 54 forks source link

Silent set functionality for objects #28

Closed Neogavin closed 11 years ago

Neogavin commented 11 years ago

Been using Stapes for a project here at work, and was wondering why this wasn't a feature already: Implement silent set functionality for objects as well as individual values.

Because sometimes, I want to update a model without having it notify everything else right away.

Also showed an alternative way to handle the silent flag existing or not.

yocontra commented 11 years ago

Doesn't this already exist? I see tests for this too

Neogavin commented 11 years ago

http://jsfiddle.net/Neogavin/3WPYS/5/

Here's a jsfiddle that shows the problem exactly. If you set/update using an object, the silent flag is ignored.

hay commented 11 years ago

Hey Neogavin, thanks for your pull request!

Right now the silent option is not just a argument for set, but also for push, remove and update. IMHO, adding the flag for objects in set would also require adding it for those three other functions. I'm not sure if the use case is big enough. Note that if you want, you can pretty easily monkeypatch Stapes to have the functionality you want using the Stapes.extend method.

Neogavin commented 11 years ago

That's how I'm currently using it on my project. I just think it'd be more consistent for the silent flag to always work, and not just in the case of setting/pushing/removing/updating one attribute. And its a small enough change that I could literally do it in a few minutes and commit it.

I can understand it not seeming like a very big use case right now, but this was something that threw me off for a while, and I am using it in a production environment, so I'm sure someone else will want this feature added in at some point. I could submit another pull request with the change already in it if needed.

yocontra commented 11 years ago

I agree with @neogavin it seems like inconsistent behavior for set to not obey the silent flag in a case as standard as this. If you want to initialize a bunch of properties on init but don't want it to trigger a bunch of events off (which seems like it is what you would want to do) it seems like overkill to write a bunch of .set calls instead of one

Neogavin commented 11 years ago

Oh, shoot, that last commit was an error, I put it on the wrong branch.

hay commented 11 years ago

Okay, the use case seems legit, and i agree that it's probably easy to implement. However, i'll only accept a pull request if:

I'll be closing this PR for now, if you got something, please open a new one. I'm looking forward to your contributions and thanks for all your comments on Stapes!

hay commented 11 years ago

Well, i was a little harsh last time, it didn't actually take the time i thought to code it, so i rolled in silent functionality for objects in set in the latest release, v0.8.0, which i've released just now! Thanks for your suggestion and PR!