Utilities to combining & compose Knockout observables
kc.fieldsexplodes an observable of an object into observables for each field.
kc.objectcombines an object of observables into an observable of an object.
kc.everycombines a list of observables into one observable that is true whenever they all are.
kc.anycombines a list of observables into one observable that is true whenever any is.
kc.togglecreates a callback to toggle a
Booleanobservable, useful for
kc.toggleFieldtoggles a field of the view model by name.
kc.monotonicObjectbuilds an object based on values it sees in an observable array (this one is a bit fancier).
kc.deepUnwraprecursively traverses a value and unwraps all the observables it sees. Especially handy for logging.
kc.wrapwraps a value in an observable if it is not already.
kc.monitorlogs every change to an observable to the console (throttled as this can be crazy).
See the code itself for more details; each function is really quite small. To be expanded as I scrape these out of my various codebases. Pull request very welcome!
Copyright & License
Copyright 2013 Kenneth Knowles
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.