Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@profiscience/knockout-contrib-utils-assign

Profiscience134WTFPL2.0.6TypeScript support: included

[![Version][npm-version-shield]][npm] [![Dependency Status][david-dm-shield]][david-dm] [![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer] [![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev] [![Downloads][npm-stats-shield]][npm-sta

readme

utils.assign

Version Dependency Status Peer Dependency Status Dev Dependency Status Downloads

This package is intended for consumption via the [@profiscience/knockout-contrib] metapackage

(Deep) Object.assign(), but updates existing observables instead of overwriting them. Simply put, updates an observable tree by merging in new values.

Usage

assign(dest, src[, options = { mapArrayElements: false, strict: false }])

For each enumerable property of src, if...
  ...value is not defined on dest and...
    ...`options.strict` is `false`, creates property as observable on `dest`
    ...`options.strict` is `true`, creates property as non-observable on `dest`
  ...value is defined and observable on `dest`
    ...`dest` observable is updated
  ...value is defined and non-observable on `dest`
    ...`dest` property is updated (not as observable)  

If mapArrayElements is true, array elements will be created as mapped observables, else bare objects/primitives. NOTE: Merging new arrays onto existing ones that have been mapped mapArrayElements will create new observable elements, not update the existing ones. No attempts are made to key elements, nor will they. If you need more, you probably want ko.mapping which is much more powerful, but far slower.

NOTE: Non-writable observables on the destination (computeds w/o write functions) will be silently ignored

import { assign } from '@profiscience/knockout-contrib'

const foos = {
  foo: ko.observable('foo'),
  bar: 'bar',
}

assign(foos, {
  foo: 'new foo',
  bar: 'new bar',
  baz: 'baz',
})
// {
//   foo: ko.observable('new foo'),
//   bar: 'new bar',
//   baz: ko.observable('baz')
// }

assign(
  foos,
  {
    foo: 'new foo',
    bar: 'new bar',
    baz: 'baz',
  },
  { strict: true }
)
// {
//   foo: ko.observable('new foo'),
//   bar: 'new bar',
//   baz: 'baz' <----------------------- When strict and observable is not pre-created on dest, property will NOT be observable
// }

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.0.6 (2020-10-09)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.5 (2019-12-12)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.4 (2019-12-12)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.3 (2019-12-12)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.2 (2019-10-22)

Bug Fixes

  • utils.assign: create object on destination if null (2c4e372)

2.0.1 (2019-06-04)

Bug Fixes

  • utils.assign: Don't blow up if destination computed is not writable (83de657)

2.0.0 (2019-02-22)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.0-rc.4 (2018-10-04)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.0-rc.3 (2018-08-08)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.0-rc.2 (2018-07-20)

Bug Fixes

  • Add babel-runtime dep, remove unnecessary tslib dep (9fca55a)

2.0.0-rc.1 (2018-07-13)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign

2.0.0-rc.0 (2018-06-28)

Chores

  • utils.*: Upgrade to KnockoutJS 3.5.0-rc (51da4b5)

BREAKING CHANGES

  • utils.*: Require Knockout 3.5.0-rc (or better) for TypeScript consumers

1.0.1 (2018-06-28)

Note: Version bump only for package @profiscience/knockout-contrib-utils-assign