Socket
Socket
Sign inDemoInstall

observable-lite

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    observable-lite

Observable object for use with rivetsjs and other libraries


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
21.2 kB
Created
Weekly downloads
 

Readme

Source

observable Build Status

Simple observable class (similar to watchjs) for use with rivetsjs and other libraries

####Simple Use

// Basic object
var myObj = {
  hello: 'world'
};

// Make the object obserable
var observe = new Observable(myObj);

function callback(value, path) {
  console.log(value, path);
}

// Listen for changes to 'hello' property
observe.subscribe('hello', callback);

// Update the value of the hello property
observe.set('hello', 'newValue'); // 'newValue', 'hello' logged to console because of subscriber

// Stop listening to changes
observe.unsubscribe('hello', callback);

####Nested Object listening

// Created Object
var nestedObj = {
  hello: {
    nested: {
      fartherNested: {
        num: 1234
      }
    }
  }
}

// Make observable
var observe = new Observable(myObj);

function callback(value, path) {
  console.log(value, path);
}

// Listen for changes to 'num' property
observe.subscribe('hello.nested.fartherNested.num', callback);

// Update the value of the 'num property
observe.set('hello.nested.fartherNested.num', 5678); // 5678, 'hello.nested.fartherNested.num' logged to console because of subscriber

// Stop listening to changes
observe.unsubscribe('hello.nested.fartherNested.num', callback);

####Subscribers

  • If a subscriber is listening to 'hello.nested.fartherNested.num' and 'hello' is set, the callback will be called
  • If a subscriber is listening to 'hello' and 'hello.nested.fartherNested' changes, the callback will be called

#####Unsubscribe from all at keypath

  • If you don't specify a callback all subscribers will be removed on that keypath
observe.unsubscribe('hello')

Keywords

FAQs

Last updated on 02 Sep 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc