Skip to content

Commit

Permalink
fix: add es6 example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickleet authored Dec 10, 2018
1 parent 473440e commit c85ab4f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ Sourced makes no assumptions about how you _store_ your events and snapshots. Th
- [sourced-repo-mongo](https://github.com/mateodelnorte/sourced-repo-mongo)
- ~~[sourced-repo-couchdb](https://github.com/dermidgen/sourced-repo-couchdb)~~ (partially implemented)

# ES6 Example

```javascript
const Entity = require('sourced').SourcedEntity;

class Market extends Entity {
constructor(snapshot, events) {
super()
this.orders = [];
this.price = 0;

this.rehydrate(snapshot, events)
}

init(param) {
this.id = param.id;
this.digest('init', param);
this.emit('initialized', param, this);
}

createOrder(param) {
this.orders.push(param);
var total = 0;
this.orders.forEach(function (order) {
total += order.price;
});
this.price = total / this.orders.length;
this.digest('createOrder', param);
this.emit('done', param, this);
};
}
```

# Reference

## Classes
Expand Down

0 comments on commit c85ab4f

Please sign in to comment.