Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kobservable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kobservable

Observable constructor with KnockoutJS style

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

K-Observable

Build Status

This is a basic observable implementation to hold data and get notified whenever it changes. Inspired by the well-known KnockoutJS observable objects, but without any other magic (like bindings or dependency tracking). Just observables and subscriptions.

Observable

The most basic unit: you can store and retrieve data from them.

import observable from 'kobservable';

const name = observable('');
name.subscribe(newName => console.log(`The new name is '${newName)}'`);
name('foo');// sets the name
//The new name is foo
name();// gets the name

Computed

Given a number of observables, you can perform some aggregation conversion and get it like another read-only observable.

import observable, {computed} from 'kobservable';

const user = observable('me');
const password = observable('me too');
const canSubmit = computed([user, password], ([user, password]) => Boolean(user && password));

const mySubmitButton = document.querySelector('#submit');
canSubmit.subscribe(can => mySubmitButton.disabled = !can);

user('');// disables the button
password('');// the button remains disabled
user('me');// the button remains disabled
password('me again');// enables the button

Powered by TypeScript

If your IDE has TypeScript running (with a plugin, see more at https://www.typescriptlang.org/), you can:

  • Code in JavaScript and see how your IDE autocompletes all the K-Observable usages, with type inferences and so on. You can see an example under the test folder.
  • Code in TypeScript and... you know, TypeScript!

Compile

npm install && npm run build

Test

npm test

FAQs

Package last updated on 17 Aug 2016

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