Skip to content

hormander/node-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Observer

This is an observer pattern module

Install

npm install node-observer

Example

Main file: app.js

"use strict";

var observer = require("node-observer");
var hello = require("./hello");

observer.subscribe(this, "HELLO", function(who, data) {
	console.log(data);
});

hello.send();

File: hello.js

"use strict";

var observer = require("node-observer");

var Hello = function() { };

Hello.prototype.send = function() {
	observer.send(this, "HELLO", "hello world!!!");
};

module.exports = new Hello();

Run

node app.js

API

subscribe(object, event, callback)

object:object, event:string, callback:function

subscribe event

unsubscribe(object, event)

object:object, event:string

unsubscribe event

send(object, event, data)

object:object, event:string, data:object

send event 'event' with data 'data'

Contributors

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published