Giter VIP home page Giter VIP logo

observable's Introduction

observable

Observable, observer capabilities built upon the observable shim

Summary

  • We need a pretty sintax to listen to single properties
  • Requirements
    • ES5 Getters and Setters (Shim ships with component, IE 10+)
    • ES7 Observer (Shim ships with component, IE ?+)

Installation

$ component install indefinido/observable

API

Functionality (Single Property, All Properties)

Just implements a nicer interface:

  require('observable');

  arthur = observable.call({
    name     : function () { return this.firstname + " " + this.surname; },
    firstname: "Arthur Philip",
    surname  : "Dent",
    species  : "Humam"
  });

  // Subscribe to all changes
  arthur.subscribe(function (updates) {
    var i = updates.length,  update;
    while (i--) {
       update = updates[i];
      console.log(update.name, update.type, update.oldValue, '→', update.object[update.name]); // also this[update.name]
    }
  });

  // Subscribe to single property change
  arthur.subscribe('firstname', function ( update) {
    console.log( update.name,  update.type,  update.oldValue, '→',  update.object[ update.name]); // also this[ update.name]
  });

! Warning all properties and configuration is stored in a per object basis on the observed property:

  require('observable');

  arthur = observable.call({
    name     : function () { return this.firstname + " " + this.surname; },
    firstname: "Arthur Philip",
    surname  : "Dent",
    species  : "Humam"
  });

  // Don't mess with this properties
  // they change between browsers!
  arthur.observed.name; // "Arthur Philip"

  // Also in some browsers it is not possible to create unreadable
  // properties, the it will apear on for in loops!
  for (attribute in arthur) {
    if (attribute == "observed") alert("Im not hidden!");
  }

Adapters

Rivets

  require('observable/adapters/rivets');

  arthur = observable.call({
    name     : function () { return this.firstname + " " + this.surname; },
    firstname: "Arthur Philip",
    surname  : "Dent",
    species  : "Humam"
  }),

  template = '<div class="person">' +
			 '  <span data-html="person.name"></span>    ' +
			 '  <span data-html="person.species"></span> ' +
			 '</div>';

  document.body.innerHTML = template;
  element = document.body.children[0];

  rivets.bind(element, {person: arthur});

  arthur.species = "Homo Sapiens";

TODO

TESTS!

A tiny part of tests has been written, but more on the go!

License

WTFPL

Credits

Built upon the lovely coffeescript language Uses heavily https://github.com/KapIT/observe-shim and https://github.com/KapIT/observe-utils

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.