Best (?) Practice for Loading and Saving Relational Data in Polymer

What's the best or just good practice for loading and storing relational data in published properties of polymer elements?

I used https://github.com/PaulUithol/Backbone-relational to load and save relational data. It depends on the trunk. But now that using Polymer's Object.observe (), I basically don't need the underlying Backbone model objects (at least I don't need the get () and set () methods), but I can't figure out how I would best get rid of the complex Backbone objects and just use plain JavaScript objects AND load and store the relational data in my datastore.

Is there a Polymer compatible library / web component that already implements this? Or your own way to do it?

Here are some ways I could do it myself without a library, but I expect I'm missing a lot of cases.

  • Loading relational data:
// Load from server
model = store.get('model-id');
// model == {'id':'abc', 'name':'Parent', child_ids:['child-id1', 'child-id2']}
for (child_id in model.child_ids){
    model.children[child_id] = store.get(child_id);
}
// Use model in Polymer element published property here

      

  1. Save relational data:
// Get model from Polymer published property here
model.child_ids = [];
for (child in model.children){
    model.child_ids.push(child.id);
}
delete model.children;
store.set(JSON.stringify(model));
// or just store.set(model);

      

+3


source to share





All Articles