Coder Social home page Coder Social logo

timreynolds / js-domain Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 187 KB

Base classes and ts declarations for using the domain model pattern with DDD in js

License: MIT License

TypeScript 100.00%
ddd ddd-patterns javascript typescript events domain-driven-design

js-domain's Introduction

JS DDD Classes

Build Status Coverage Status

A set of base classes used to implement DDD style domain model pattern in JavaScript.

Classes

Below outlines the classes provided in this package and the functionality encapsulated in each.

Value Object

Objects that matter only as the combination of their attributes. Two value objects with the same values for all their attributes are considered equal.

Provides a createdOn date which is can either be set via the constructor or defaults to Moment utc.

Entity

Objects that have a distinct identity that runs through time and different representations.

Extends ValueObject but provides an id to distinguishes the objects identity throughout time. Defaulted to a v4 GUID when not provided.

Aggregate Root

Cluster of domain objects that can be treated as a single unit and the basic element of transfer of data storage.

Extends Entity with the additional responsibility of tracking and queuing Events.

Within these classes the Aggregate takes responsibility for eventing for any entity it manages. Events are stored within the class and made accessible vis the enqueuedEvents method. The advantages of this approach are;

  • Class isn't coupled to a publisher
  • Events can be batched processed
  • Events can be encapsulated within a transactional boundary

Event

Captures the memory of something interesting which affects the domain

Used to provide a consistent interface for events from the domain expecting a type and data properties via the constructor. The following common event properties are default unless provided;

  • id
  • correlationId
  • raisedOn

Intended to be extended by specific event classes that include data validation.

#Example Usage

All classes are exposed at root level.

const { ValueObject } = require('@reynolds/domain');
class Example extends ValueObject {

As are typescript declarations

const { ICreatedOn } = require('@reynolds/domain');
class Example implements ICreatedOn {}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.