angularLocalStorage icon indicating copy to clipboard operation
angularLocalStorage copied to clipboard

Feature Suggestions

Open OpherV opened this issue 12 years ago • 4 comments

Nice library! :)

Two suggestions:

  1. Specifying a watch on a property in localStorage, so that if that property changes, the scope model changes as well. This is useful when using localStorage to sync the state of your app across multiple browser windows.
  2. An option to select how to resolve conflicts on binding. For example, when binding a property on the scope to a localStorage property, if both exist and have different data, you might want to choose which takes precedence. (IE which of the different values is "true", the localStorage one or the scope on)

OpherV avatar Jul 23 '13 13:07 OpherV

As far as the localStorage watching we can use something like: http://stackoverflow.com/questions/4679023/bug-with-chromes-localstorage-implementation/4679754#4679754 or http://typeofnan.blogspot.com/2010/09/localstorage-inter-window-communication.html the specification for this feature can be found here http://dev.w3.org/html5/webstorage/#localStorageEvent

I think the only down side would be older browsers not supporting this, so we will need to also try to find a way to watch cookies. Maybe this http://stackoverflow.com/questions/4132561/is-there-a-way-to-listen-to-event-when-a-cookie-is-changed-in-a-firefox-extensio

But I do like that all tabs will instantly update and shoot off an event.

I am not sure about the override protection against conflicts... can you please list some possible real life scenarios?

agrublev avatar Jul 23 '13 15:07 agrublev

Sounds good!

For the conflict resolution: Let's say you have a web app that uses localStorage to be able to work while offline. The user might work on something, save it to localStorage, then when internet access is once again available, data is fetched from the server to the scope. At this point the new data fetched from the server is actually stale, so you need to make sure the data in the scope is the "newer" one, coming from localStorage

OpherV avatar Jul 25 '13 07:07 OpherV

I think this may go beyond the functionality of this module and here is my reasoning: User goes offline and does some editing, while he is offline his colleagues from the office make changes to the same item, so now that he connects to the internet we cannot assume his change is the one that must be pushed online... mainly because I can imagine someone closing the laptop, then working on his home computer for a couple days, and then as soon as he opens the laptop and it connects to the internet it will override all of his new changes.

Managing this sort of functionality I believe requires a module on its own with amazing cache validation, and ability to timestamp all the stuff stored in the localStorage and also make sure server requests return a specific lastModified date. I'm not saying it's a bad idea, but it just feels beyond the scope of this module.

agrublev avatar Jul 25 '13 15:07 agrublev

I see what you're saying.

Well in any case one could easily achieve the appropriate behaviour for his\her app by checking localStorage vs scope values and resolving the conflict prior to binding.

Thanks for considering :)

OpherV avatar Jul 30 '13 08:07 OpherV