New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eventric

Package Overview
Dependencies
Maintainers
3
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventric

behavior-first application development

  • 0.16.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
69
decreased by-40%
Maintainers
3
Weekly downloads
 
Created
Source

Not production ready. API might change heavily.

eventric logo

eventric.js Build Status

Behavior-first application development. Runs on NodeJS and modern Browsers.

Philosophy

Early talk about MVC, CRUD, DDD, CQRS and Event Sourcing from Johannes Becker, original creator of eventric: http://www.youtube.com/watch?v=XSc7NPedAxw

Getting started

npm install eventric

Important: eventric requires Promises. If you have to support older browsers use the es6-promise polyfill.

Setup Context

Having discussed the upcoming TodoApp Project with the Business-Experts and fellow Developers it got clear that we should start with a Context named Todo.

eventric = require('eventric');

todoContext = eventric.context('Todo');

Define the Event

Inside of our Todo Context things will happen which are called DomainEvents. A technique to come up with these is called EventStorming. Lets add two called TodoCreated and TodoDescriptionChanged.

todoContext.defineDomainEvents({
  TodoCreated: function(params) {},
  TodoDescriptionChanged: function(params) {
    this.description = params.description;
  }
});

Adding an Aggregate

Now we need an Aggregate which actually raises this DomainEvents.

todoContext.addAggregate('Todo', function() {
  this.create = function() {
    this.$emitDomainEvent('TodoCreated');
  }
  this.changeDescription = function(description) {
    this.$emitDomainEvent('TodoDescriptionChanged', {description: description});
  }
});

Hint: this.create is called by convention when you create an aggregate using this.$aggregate.create

Hint: this.$emitDomainEvent is dependency injected

Adding CommandHandlers

To actually work with the Context from the outside world we need CommandHandlers. Let's start by adding a simple one that will create an instance of our Todo Aggregate.

todoContext.addCommandHandlers({
  CreateTodo: function(params) {
    return this.$aggregate.create('Todo')
    .then(function (todo) {
      return todo.$save();
    });
  }
});

Hint: this.$aggregate is dependency injected

It would be nice if we could change the description of the Todo, so let's add this CommandHandler too.

todoContext.addCommandHandlers({
  ChangeTodoDescription: function(params) {
    return this.$aggregate.load('Todo', params.id)
    .then(function (todo) {
      todo.changeDescription(params.description);
      return todo.$save();
    });
  }
});

Subscribe to a DomainEvent

And last but not least we want to console.log when the description of the Todo changes.

todoContext.subscribeToDomainEvent('TodoDescriptionChanged', function(domainEvent) {
  console.log(domainEvent.payload.description);
});

Executing Commands

Initialize the Context, create a Todo and tell the Todo to change its description.

todoContext.initialize()
.then(function() {
  return todoContext.command('CreateTodo');
})
.then(function(todoId) {
  return todoContext.command('ChangeTodoDescription', {
    id: todoId,
    description: 'Do something'
  });
});

After executing the Commands the DomainEventHandler will print Do something. Your Todo Aggregate is now persisted using EventSourcing into the InMemory Store.

Running Tests

To execute all (client+server) tests, use:

gulp spec

You can watch for file-changes with

gulp watch

Release

gulp bump:patch
git add .
git commit -m"$VERSION"
git push
npm publish
git checkout -b release master
git add build -f
git commit -m"$VERSION"
git tag $VERSION
git push --tags
git checkout master
git branch -D release

License

MIT

Copyright (c) 2013-2015 SixSteps Team, eFa GmbH

Keywords

FAQs

Package last updated on 06 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc