UNPKG

@commodo/fields

Version:

Enables defining rich data models by decorating function instances with specified model fields. Additionally, it adds `populate` and `validate` methods, for populating model instances with data, and then validating it, respectively.

36 lines (28 loc) 807 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _repropose = require("repropose"); function isPromise(value) { return Boolean(value && typeof value.then === "function"); } const onSet = callback => { return (0, _repropose.withProps)(props => { const { setValue } = props; return { setValue(value) { const newValue = callback(value); if (isPromise(newValue)) { throw new Error(`A promise was returned from the "onSet" callback (applied on the "${props.name}" field). Provided callbacks cannot perform async operations.`); } return setValue.call(this, newValue); } }; }); }; var _default = onSet; exports.default = _default; //# sourceMappingURL=onSet.js.map