ember-data-model-maker icon indicating copy to clipboard operation
ember-data-model-maker copied to clipboard

Add persistence via serialization of model structure in URL

Open manmal opened this issue 10 years ago • 2 comments

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.

manmal avatar Jun 11 '14 06:06 manmal

This seems like it could work pretty well with queryParams. Hopefully can look into this soon.

andycrum avatar Jul 02 '14 03:07 andycrum

Is there not a limit on the length of a query string? What would happen when the models exceeded this length?

jackmatt2 avatar Feb 07 '16 06:02 jackmatt2