UNPKG

@paperbits/core

Version:
21 lines (17 loc) 506 B
import * as ko from "knockout"; ko.extenders.max = (target, max) => { const result = ko.pureComputed({ read: target, write: (newValue) => { const current = target(); if (newValue <= max) { target(newValue); } else if (newValue !== current) { target.notifySubscribers(newValue); } } }).extend({ notify: "always" }); result(target()); return result; };