Skip to content

Instantly share code, notes, and snippets.

@otaviosoares
Created July 19, 2016 19:28
Show Gist options
  • Save otaviosoares/8de65fc4cec1ac89cb66786a913ec41c to your computer and use it in GitHub Desktop.
Save otaviosoares/8de65fc4cec1ac89cb66786a913ec41c to your computer and use it in GitHub Desktop.
var entity = seneca.make('cliente')
entity.name = 'Otavio'
entity.save$(function(err) {
console.log('saved')
})
// Collection cliente
//id name
//1 Otavio
entity.load$({name: 'Otavio', function(err, entity) {
console.log('loaded the entity', entity)
})
var sourced = seneca.make_sourced('cliente')
sourced.digest('name-added', {name: 'Otavio'})
sourced.commit()
// Collection client events
//id event version data
//1 name-added 1 {name: 'Otavio'}
var cliente = new Cliente()
user.addName({name: 'Otavio'})
sourcedRepository.commit(cliente, function() {
// raises name-added
})
function Cliente () {
this.name = ''
Sourced.apply(this, arguments)
}
util.inherits(Cliente, Sourced)
Cliente.prototype.addName = function (param) {
this.name = param.name
this.digest('name-added', param)
this.enqueue('name-added', param, this)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment