-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model Sync Local Storage - sync layer for Model and ModelList #190
Conversation
(Keeping a record of what we decided in IRC) @clarle Looks good on first glance! But let's keep iterating on this in Gallery and put it through its paces some more. We'll plan on merging this in for 3.7.0pr1. |
|
||
component=model-sync-local | ||
component.jsfiles=model-extensions/model-sync-local.js | ||
component.requires=model, model-list, json-stringify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to explicitly require model-list
. I left it out of ModelSync.REST's requirements too.
Looks great! |
@juandopazo and anyone else interested in testing it out, ModelSync.Local is available in the Gallery here: |
I'm totally using this for a new project :) |
this.storage = Y.config.win.localStorage; | ||
store = this.storage.getItem(this.root); | ||
} catch (e) { | ||
Y.log("Could not access localStorage.", "warn"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you propose to use the extension? Like this?
var exts = [];
if (Y.config.win.localStorage) {
exts.push(Y.ModelSync.Local);
}
var Foo = Y.Base.create('foo', Y.Model, exts)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should fall back to an in-memory store if Y.config.win.localStorage
is not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to use Y.CacheOffline
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericf and I discussed this before, and we decided that Y.CacheOffline
had too much overhead and not all of the parts in it would be needed for ModelSync.Local
, so just a quick re-implementation of the core portion of it would be fine. Any thoughts on your side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I was thinking exactly the same. Let me know if I you need help with the implementation.
A quick update: I am going to need to wait until after this sprint to pull this in (code freeze is this Friday, 9/7). That said, I've been thinking about using
|
\o/ Thanks for tackling my problems! |
Yeah, I understand, it's for the better. I've made some changes to the Gallery version of LocalStorage that I haven't synced up to this PR yet, my apologies. I still need to do more testing on it myself in the meantime and write user documentation for it. There might be a fairly major API change for this module (I forgot about the use case where people can have multiple ModelLists that share the same Model), so that's one thing I need to work on. |
@triptych Yep, sounds good to me. |
Looks like I'm probably too late for this release, but here goes:
This provides Y.ModelSync.Local, an extension which provides a sync implementation through locally stored
key value pairs, either through the HTML localStorage API or falling back onto an in-memory cache, that can be mixed into a Model or ModelList subclass.
A group of Models/ModelLists is serialized in localStorage by either its class name, or a specified 'root' that is provided.
Example Usage
To-do
Has API docs, high test coverage, and is only missing user documentation. However, there is an example writen for TodoMVC that can be found here:
https://github.com/clarle/todomvc/tree/yui-3.6.0/architecture-examples/yuilibrary