UNPKG

ruddy

Version:

Modularized state-management tools for modern front-end applications. Manage dispatched messages in a clean and predictable way for either small or large scale projects

129 lines (122 loc) 7.99 kB
import _default22 from 'ramda/src/none'; import _default21 from 'ramda/src/complement'; import _default20 from 'ramda/src/difference'; import _default19 from 'ramda/src/keys'; import _default18 from 'ramda/src/isEmpty'; import _default17 from 'ramda/src/allPass'; import _default16 from 'ramda/src/filter'; import _default15 from 'ramda/src/split'; import _default14 from 'ramda/src/last'; import _default13 from 'ramda/src/map'; import _default12 from 'ramda/src/equals'; import _default11 from 'ramda/src/uniq'; import _default10 from 'ramda/src/length'; import _default9 from 'ramda/src/toPairs'; import _default8 from 'ramda/src/values'; import _default7 from 'ramda/src/compose'; import _default6 from 'ramda/src/anyPass'; import _default5 from 'ramda/src/all'; import _default4 from 'ramda/src/is'; import _default3 from 'ramda/src/both'; import _default2 from 'ramda/src/either'; import _default from 'ramda/src/identity'; import { areStateNamesStrings, areInputsAndTransitionsStrings, getStateMachinesPropPath, isEachTransitionAmongMachineStates } from '../machines'; import { createConstants } from '../types'; import { isSpecOrFunction, isEffect, isEnhancer, isNotEmpty, isPrimitiveish, isPlainObj, isGoodString } from '../util/is'; import { isValidationLevel, makeValidationLevel } from '../validators'; /** * This object of functions is meant to be applied to an object which has * some or all of its keys sharing the same name as these evolver functions. * * Using [evolve()](http://ramdajs.docs/#evolve) on an object with this set of evolver functions * will create a clone of the original object with the result of each evolver in place of the original value. */ export var metadataEvolvers = { namespace: _default, store: _default, validationLevel: makeValidationLevel, stateMachinesPropName: getStateMachinesPropPath, consts: createConstants /** * These are values which will always be set for a new duck, * even though the user may not explicitly supply a value for any of them. */ };export var duxDefaults = { consts: {}, creators: {}, machines: {}, queries: {}, workers: {}, selectors: {}, stateMachinesPropName: 'states', types: [], validationLevel: 'CANCEL', validators: {} /** * This set of rules is expected to be supplied to the (curried) [spected](https://github.com/25th-floor/spected) * function, and is then invoked against the set of values supplied when creating a new duck. * * The spected validator function will then apply this collection of validator functions against * any matching keys on the input values passed in, and set either a value of 'true' if validation succeeded * or an array of error messages for any value(s) that failed validation. */ };export var duxRules = { validationLevel: [[isValidationLevel, 'must be: STRICT, CANCEL, PRUNE, or LOG. CANCEL is the default.']], store: [[isGoodString, 'must be a (non-blank) string']], namespace: [[isGoodString, 'must be a (non-blank) string']], stateMachinesPropName: [[_default2(isGoodString, _default3(_default4(Array), _default5(isGoodString))), 'must be a string (or array of strings)']], consts: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], creators: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], machines: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], selectors: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], types: [[_default3(_default4(Array), _default5(_default4(String))), 'must be an object (or a function returning an object)']], validators: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], multipliers: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], queries: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], workers: [[_default2(isPlainObj, _default4(Function)), 'must be an object (or a function returning an object)']], reducer: [[_default4(Function), 'must be a function']], enhancers: [[_default6([_default4(Function), _default3(isPlainObj, _default7(_default5(isSpecOrFunction), _default8)), _default3(_default4(Array), _default5(isEnhancer))]), 'must be an array of key/value pairs, an object (or a function returning one of those options)']], effects: [[_default2(_default4(Function), _default3(_default4(Array), _default5(isEffect))), 'must be an array of key/value pairs (or a function returning an one)']], throttling: [[_default2(_default3(_default4(Array), _default5(_default4(Array))), _default4(Function)), 'must be an array of key/value pairs (or a function returning an one)']], debouncing: [[_default2(_default3(_default4(Array), _default5(_default4(Array))), _default4(Function)), 'must be an array of key/value pairs (or a function returning an one)']], initialState: [[_default6([isPrimitiveish, isPlainObj, _default4(Function)]), 'must be an object, a function returning an object, or a primitive value']] /** * This set of rules is expected to be supplied to the (curried) [spected](https://github.com/25th-floor/spected) * function, and is then invoked against one or more ducks supplied to the validator middleware. * * The spected validator function will then apply this collection of validator functions against * any matching keys on the input values passed in, and set either a value of 'true' if validation succeeded * or an array of error messages for any value(s) that failed validation. * * The validator middleware makes use of a small portion of a given duck, so the schema rules * for validating a usable duck in the middleware function is less strict than those used to create a duck. */ };export var duckMiddlewareRules = { store: [[isGoodString, 'must be a (non-blank) string']], namespace: [[isGoodString, 'must be a (non-blank) string']], types: [[isPlainObj, 'must be an object'], [_default7(_default5(_default7(_default12(1), _default10, _default11)), _default13(function (_ref) { var key = _ref[0], val = _ref[1]; return [key, _default7(_default14, _default15('/'))(val)]; }), _default16(_default5(_default4(String))), _default9), 'each key and value are identical']], machines: [[_default7(_default5(isPlainObj), _default8), 'must be an object'], [_default7(_default5(isNotEmpty), _default8), 'must not be empty'], [_default7(_default5(_default17([areStateNamesStrings, areInputsAndTransitionsStrings])), _default8), 'each machine contains nested objects (states) whose inputs and transitions are strings'], [_default7(_default5(isEachTransitionAmongMachineStates), _default8), 'each transition value must also be a state']], stateMachinesPropName: [[_default3(_default4(Array), _default5(isGoodString)), 'must be an array of strings (representing the path to the "current state" prop)']] /** * Checks to see if a given value is a Duck for middleware, * which means it is a namespaced unit that contains types and validators for one or more of those types. * * @func * @sig * -> Boolean * @param {*} val A value which may or may not be a Duck instance * @returns {Boolean} whether or not the object is an instance of a Duck */ };export var isDux = _default7(_default18, _default20(['store', 'namespace', 'validators', 'types']), _default19); /** * Checks whether or not a given Object contains ducks * * @func * @sig {k: v} -> Boolean * @param {Object} row An Object which may contain ducks among its props * @returns {Boolean} whether or not there are any ducks inside of a given Object */ export var noDucks = _default6([_default21(isPlainObj), _default7(_default18, _default19), _default7(_default22(isDux), _default8)]);