spine / spine

Lightweight MVC library for building JavaScript applications

Home Page:http://spine.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Model.refresh() breaks existing record clones

adambiggs opened this issue · comments

I just stumbled upon an interesting bug...

When Model.refresh() replaces a record in Model.irecords (the "master" object used as prototype for clones), any existing clones are then orphaned - Their prototype still points to the previous instance that no longer exists in Model.irecords.

So if a controller is storing a record clone, and that record is then refreshed, the clone won't contain any of the refreshed values, and also won't receive any future updates... Also, this seems like a potential memory leak.

A possible fix might be to reuse existing objects in Model.irecords instead of removing them and replacing them with new instances.

hmmm.... seems like it would not be to tricky to write a test. I will see if I can do that in a few days if you don't get to it first.

BTW. I am working on updating tests to jasmine 2.0. some nice little improvements.

Sounds good!

Side note - If you're already updating the tests, do you think it would be a good idea to convert them to CoffeeScript? Personally, it feels kind of weird writing tests in plain old JS :neckbeard:

Started the model-refresh-bug branch to investigate further.

It would be a good idea, I will see if I can do it quickly. otherwise it will have to go on the list of 'when I have time to burn'

Converting the tests might be pretty simple with js2coffee.