Socket
Socket
Sign inDemoInstall

observ-struct

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    observ-struct

An object with observable key value pairs


Version published
Weekly downloads
270
decreased by-44.1%
Maintainers
1
Install size
29.4 kB
Created
Weekly downloads
 

Readme

Source

observ-struct

An object with observable key value pairs

Example

An observable will emit a new immutable value whenever one of its keys changes.

Nested keys will still be the same value if they were not changed in that particular .set() call.

var ObservStruct = require("observ-struct")
var Observ = require("observ")
var assert = require("assert")

var state = ObservStruct({
    fruits: ObservStruct({
        apples: Observ(3),
        oranges: Observ(5)
    }),
    customers: Observ(5)
})

state(function (current) {
  console.log("apples", current.fruits.apples)
  console.log("customers", current.customers)
})

state.fruits(function (current) {
  console.log("apples", current.apples)
})

var initialState = state()
assert.equal(initialState.fruits.oranges, 5)
assert.equal(initialState.customers, 5)

state.fruits.oranges.set(6)
state.customers.set(5)
state.fruits.apples.set(4)

Docs

var obj = ObservStruct(opts)

ObservStruct() takes an object literal of string keys to either normal values or observable values.

It returns an Observ instance obj. The value of obj is a plain javascript object where the value for each key is either the normal value passed in or the value of the observable for that key.

Whenever one of the observables on a key changes the obj will emit a new object that's a shallow copy with that key set to the value of the appropiate observable on that key.

Installation

npm install observ-struct

Contributors

  • Raynos

MIT Licenced

FAQs

Last updated on 08 Oct 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