Socket
Socket
Sign inDemoInstall

computed-observable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

computed-observable

An approximate impementation of computed observables


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

#computed observable

npm install computed-observable

An approximate implementation of Knockout's computed observables.

##Usage

  var CO = require('computed-observable');

A somewhat familiar interface

Note that you don't have to invoke this.firstName or this.lastName within the computed function. Just reference the variables naturally. The same goes for assignment. Notice that we use person.firstName = instead of invoking some setter function.

  function Person() {
    this.observable('firstName', 'Bobby');
    this.observable('lastName', 'Stevenson');
    this.computed('fullName', function() {
      return this.firstName + ' ' + this.lastName;
    });
  };

  var person = new CO(Person);

  person.on('changed', function() {
    console.log('Model changed', this.fullName);
  });

  person.firstName = 'Stanislaw';

An unfamiliar interface

You can give CO an initialization function, or an object containing properties.


var person = new CO({
  firstName: 'Bobby',
  lastName: 'Stevenson',
  fullName: function() {
    return this.firstName + ' ' + this.lastName;
  }
});

person.on('changed', function() {
  //this.fullName === 'Stanislaw Stevenson'
});

person.firstName = 'Stanislaw';

Here, it's assumed that function properties are meant to be dynamic (computed), while other attributes are meant to be observable. This reduces boilerplate significantly.

##License

MIT

Keywords

FAQs

Package last updated on 08 Jan 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc