honeinc / hone-sdk

JavaScript library to interact with hone iframe
2 stars 0 forks source link

Delver datastore #14

Open jcblw opened 9 years ago

jcblw commented 9 years ago

so with our current datastore we have the ability to use delver to modify the object, with this datastore we do not. I was wondering if there is a good way to do this. Right now im thinking about doing something like this.

var quiz = app.hone.state( 'quiz' );
quiz = new Delver( quiz );
quiz.set( key, value );
quiz._object.save( callback );

It seems kinda hacky, but since I have the keys as strings ( just about everywhere ) I was wondering if there is a better solution for this.

andyburke commented 9 years ago

We could:

1) Wrap the quiz in a Delver object before storing it into app.hone.state each time. We could also alias quiz._object.save to quiz.save on that Delver object.

2) We could just use Delver to write into the object, eg:

Delver.set( quiz, key, value );
var foo = Delver.get( quiz, key );
jcblw commented 9 years ago

so the current solution im using is I have a utility function to do this.

// sets key strings eg 'outcomes[0].photo' and sets them to an object 
exports.setKeyString = function( key, value, obj ) {
    var _obj = new Delver( obj );
    _obj.set( key, value );
    return obj;
};

// gets key strings eg 'outcomes[0].photo' and sets them to an object 
exports.getKeyString = function( key, obj ) {
    var _obj = new Delver( obj );
    return _obj.get( key, value );
};

maybe that can be in the sdk but as the get set methods.