Giter VIP home page Giter VIP logo

microobservables's Introduction

Micro Observables

Tiny simple observables heavily based on [riot.js] 1 observables and jQuery/Zepto events, but without any dependencies.

Installation

Just copy the microObservables.js file into your project directory.

Usage

When working in Node.JS, you must call the following to use it in your project.

var observable = require("./microObservable.js");

For a HTML project, you can include it as follows:

<script src="./microObservables.js"></script>

Now you are ready to begin, you can call observable passing any POJO that you want to be able to observe.

function MyObject () {
	observable(this);
};

Then add handlers to an instance of you POJO.

var x = new MyObject();
x.on("yourEventName", function () {
	// Do something
});

and trigger an event to call your handler

x.trigger("yourEventName");

You can also pass arguments to your handlers using triggers

x.on("anotherEventName", function (x) {
	// Do something
});

x.trigger("anotherEventName", 1);

You can remove handlers by event name. for example the code below will remove all the handlers for "yourEventName"

x.off("yourEventName");

And finally all the functions are composable, so you can do things like this

x.on("event1", function () {
	// do something
}).on("event2", function () {
	// do something
});

Running the tests

This requires that you have both [npm] 2 and [grunt-cli] 3 installed.

  1. Download the latest code
  2. Run npm install
  3. run grunt test

microobservables's People

Contributors

jajeffries avatar

Watchers

James Cloos avatar Aviv Beeri 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.