Which is the best way to keep a dictionary in sync with a local shared object?
In one of the classes in my Flex application I have a dictionary, which is periodically updated from other parts of the application. It contains some sort of user preferences and I want to keep it in sync with a local shared object - the dictionary needs to be read during the class initialization and saved to the local storage when an element is changed, added or deleted.
The "Dictionary" object inherits only "Object" and does not have a change event - like the "collectionChange" in ArrayCollection. So I can't sync the dictionary just by listening for an event and manipulating the shared object in the event handler.
The other possible solution would be to make the dictionary private and manipulate it using special methods in my class. Something like:
public function setValue(key:String, value:String):void
public function getValue(key:Strin开发者_如何学编程g):String
public function delValue(key:String):void
But using bindings will become a real nightmare and I will have to make changes in many other parts of the application.
How would you sync the dictionary with the local storage? Any ideas will be appreciated. Thanks in advance!
Hum, interesting problem. Personally, I think you'll need to re-architect your data structure properly by using finalized properties instead of dynamic properties.
In the meantime however, I think your only option without completely rewriting everything would be to set a timer within the dictionary that runs every x seconds and syncs up with the shared object. This is NOT ideal for many reason, but it will work in the meantime until you finalize a better data model for your application.
i'd try to use bindSetter
精彩评论