Git Product home page Git Product logo

backbone.wreqr's Introduction

Backbone.Wreqr

A simple infrastructure based on messaging patterns and service bus implementations for decoupling Backbone and Backbone.Marionette applications.

Downloads And Source

Grab the source from the src folder above. Grab the most recent builds from the links below.

Standard Builds

RequireJS (AMD) Builds

Basic Use

Event Aggregator

An event aggregator implementation. It extends from Backbone.Events to provide the core event handling code in an object that can itself be extended and instantiated as needed.

var vent = new Backbone.Wreqr.EventAggregator();

vent.on("foo", function(){
  console.log("foo event");
});

vent.trigger("foo");

Commands And Request / Response

Wreqr can be used by instantiating a Backbone.Wreqr.Commands or Backbone.Wreqr.RequestResponse object. These objects provide an addHandler method to add a handler for a named request or command. Commands can then be executed with the execute method, and request/response can be done through the request method.

Commands

var commands = new Backbone.Wreqr.Commands();

commands.addHandler("foo", function(){
  console.log("the foo command was executed");
});

commands.execute("foo");

Request/Response

var reqres = new Backbone.Wreqr.RequestResponse();

reqres.addHandler("foo", function(){
  return "foo requested. this is the response";
});

var result = reqres.request("foo");
console.log(result);

Removing Handlers

Removing handlers for commands or requests is done the same way, with the removeHandler or removeAllHandlers functions.

reqres.removeHandler("foo");

commands.removeAllHandlers();

Extending Wreqr Objects

The EventAggregator, Commands and RequestResponse objects can all be extended using Backbone's standard extend method.

var MyEventAgg = Backbone.Wreqr.EventAggregator.extend({
  foo: function(){...}
});

var MyCommands = Backbone.Wreqr.Commands.extend({
  foo: function(){...}
});

var MyReqRes = Backbone.Wreqr.RequestResponse.extend({
  foo: function(){...}
});

License

MIT - see LICENSE.md

backbone.wreqr's People

Contributors

sontek avatar zerkalica avatar

Watchers

 avatar  avatar  avatar

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.