knockout-contrib

:metal: KnockoutJS Goodies Monorepo

View the Project on GitHub Profiscience/knockout-contrib

utils.modify

Version Dependency Status Peer Dependency Status Dev Dependency Status Downloads

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

Modifies an observable using a transform function. Returns the new value.

Useful for wrapping general purpose utilities functions for Knockout observables.

Usage

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

const foobar = ko.observable('foobar')

function reverseString(str) {
  return str.split('').reverse().join('')
}

const ret = modify(foobar, reverseString)
;(foobar() === ret) === 'raboof'