npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone-cqrs-npm

v0.5.5

Published

Project goal is to simplify the usage of the CQRS Pattern under backbone.js by providing needed infrastructure. Available over npm

Downloads

2

Readme

Introduction

Project goal is to simplify the usage of the CQRS Pattern under backbone.js by providing needed infrastructure.

Samples

Usage

To use CQRS on the clientside and inside Backbone.js we will need to push events to the browser. You can achieve this via websockets, flash, long polling or any other technique around.

INITIALIZATION

To configure Backbone.CQRS you got to init the Backbone.CQRS.hub.

// given your events look something like this
var event = {
	name: 'personChanged', // the unique name of this event
	payload: {
		id: 'someId', // the provided id should match the Backbone.Model.Id
		anotherValue: 'something'
	}	
};

// you can go with defaults
Backbone.CQRS.hub.init();

// override Backbone.sync with CQRS.sync which allows only GET method
Backbone.sync = Backbone.CQRS.sync;

There are a few options you can pass in on init. You find more information here.

Wire up commands and events to/from sever

The interface to Backbone.CQRS is provided through Backbone.CQRS.hub:

// pass in events from your socket
mySocket.on('events', function(data){
	Backbone.CQRS.hub.emit('events', data);
});

// pass commands to socket
Backbone.CQRS.hub.on('commands', function(data) {
	mySocket.emit('commands', data);
});

EVENT HANDLING

Denormalize event data

First create a denormalizer:

// personChange event
var personCreatedHandler = new Backbone.CQRS.EventDenormalizer({
    forModel: 'person',
    forEvent: 'personChanged'
});

var person = Backbone.Model.extend({modelName: 'person'});

var me = new person({id: '1'});
me.bindCQRS();

all personChanged events payload attributes for id = 1 will be applied to the personModel by simply set the event data to the model.

For events that create or delete a model you can create your denormalizer like this:

// personCreated event
var personCreatedHandler = new Backbone.CQRS.EventDenormalizer({
    methode: 'create',     // change methode to create
    model: Person,         // pass in model you want create with eventdata
    collection: persons,   // pass in collection or function returning collection you want to add to

    // bindings
    forModel: 'person',
    forEvent: 'personCreated'
});

// personDeleted event
var personDeletedHandler = new Backbone.CQRS.EventDenormalizer({
    methode: 'delete', // change methode to delete (will call unbindCQRS and destroy on model)

    // bindings
    forModel: 'person',
    forEvent: 'personDeleted'
});

For advanced options for denormalizing look here.

COMMAND HANDLING

send commands

To send commands just:

var cmd = new Backbone.CQRS.Command({
    name: 'changePerson',
    payload: {
        id: 8,
        name: 'my name'
    }
});

// emit it
cmd.emit();

You can react on an event responding to a command. Find more information here.

License

Copyright (c) 2011 Jan Mühlemann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.