JSPM

soft-update-struct

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q40571F
  • License MIT

Recursively update an observ-struct, only setting values that changed

Package Exports

  • soft-update-struct

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (soft-update-struct) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

soft-update-struct Build Status

Recursively update an observ-struct, only setting values that changed

Install

$ npm install --save soft-update-struct

Usage

var softUpdateStruct = require('soft-update-struct')
var Struct = require('observ-struct')
var Observ = require('observ')

var struct = Struct({
  foo: Observ(1),
  bar: Observ(2),
  baz: Observ(3)
})

softUpdateStruct(struct, {
  foo: 2,
  bar: 2
})

struct() // => {foo: 2, bar: 2, baz: 3}

API

softUpdateStruct(struct, [data], [compareFn]) -> struct / function

Recursively updates values in struct from data, only calling set on values that have changed.

struct

Required Type: function

An observable struct.

data

Type: object

The data to use to update the struct. All keys must have already been defined as observables in the struct. If data is omitted, a partially applied function that takes a data argument will be returned.

compareFn

Type: function compare (a, b) -> Boolean

By default, changes are detected through an equality-by-reference check (===). Pass in a custom compareFn to change the change detection logic.

License

MIT © Andrew Joslin