Skip to content

Instantly share code, notes, and snippets.

@jiggliemon
Last active December 14, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiggliemon/5009595 to your computer and use it in GitHub Desktop.
Save jiggliemon/5009595 to your computer and use it in GitHub Desktop.
var Obj = require('parsed/object')
var LocalStorage = require('parsed/object/localstorage')
var Validation = require('parsed/object/validation')
var Task = Obj.create('Task', {
implement: [LocalStorage, Validation]
}, {
init: function () {
}
})
var LocalStorage = function () {
}
LocalStorage.prototype = {
listeners: {
'saved':'save'
},
save: function (err, data) {
if (!err)
localStorageAllTheThings(data)
}
}
var Validate = function () {
}
Validate.prototype = {
listeners: {
'data.set':'validate'
'init': 'setup'
},
setup: function () {
},
validate: function (key, data) {
if (this.rules[key]) {
// somehow validate this junk.
// otherwise throw an error?
}
}
}
@GCheung55
Copy link

Then in init i would do:

init: function(){
    this.setupLocalStorage(options);
    this.setupValidation(options);
},

set: function(key, value){
    // assuming access to parent class object
    // this would validate because we've setup validation.
    // and if we're using emitting events in the "parent" set method,
    // then setupLocationStorage would be written to attach itself to the events
    // emitted by the set method.
    if (this.validate(key, value)) this.parent('set', key, value);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment