ember-data-model-maker
ember-data-model-maker copied to clipboard
Add persistence via serialization of model structure in URL
In order to allow users to share and bookmark the models they created, the model's state could be reflected in the app's URL. A viable path could be to serialize the model into JSON and BASE64 it and insert the result as a GET parameter. While running, the app can update the URL after a timeout (e.g. 1 second after the last change by the user) to reflect the new state.
The challenge here is that the update of the serialized model in the URL should not trigger a route transition, or the user will constantly be redirected and a lot of serialization and deserialization will happen every other second. According to a StackOverflow answer (http://stackoverflow.com/a/22160210/458603), this can be prevented by just changing the URL without triggering a transition:
// Modern browsers
Ember.run(function(){
window.history.replaceState( {} , 'foo', '/foo' );
});
// Legacy browsers
Ember.run(function(){
location.hash = 'foo';
});
I might submit a PR if I find some time, but can't promise it yet.
This seems like it could work pretty well with queryParams. Hopefully can look into this soon.
Is there not a limit on the length of a query string? What would happen when the models exceeded this length?