How to use property-expr - 10 common examples

To help you get started, we’ve selected a few property-expr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jquense / react-input-message / example / dev.jsx View on Github external
validate( path, input) {
    // The state is updated by widgets, but isn't always synchronous so we check _pendingState first
    var state = this._pendingState || this.state 

    // `reach()` pulls out a child schema so we can test a single path
    var field = yup.reach(schema, path)

    // we also need the specific value for this path
    var value = getter(path)(state);

    return field.validate(value, { strict: true })
      .then(() => void 0)       // if valid return nothing
      .catch(err => err.errors) // if invalid return the errors for this field
  },
github jquense / react-input-message / example / dev.jsx View on Github external
createHandler(path){
    var self = this
      , setpath = setter(path)

    return function(val){
      var s = self.state; // copy state so we can update without mutating

      if( val && val.target) // in case we got a `SyntheticEvent` object 
        val = val.target.value

      setpath(s, val === null ? undefined : val) // i don't want to allow nullable values so coerce to undefined
      self.setState(s)
    }
  },
github jquense / react-input-message / example / input-validator-example.jsx View on Github external
return val => {
        if (val && val.target) // in case we got a `SyntheticEvent` object; react-widgets pass the value directly to onChange
          val = val.target.value

        setter(path)(this.state, val)
        this.setState(this.state, () => this._runValidations())
      }
    }
github jquense / react-input-message / dev / input-validator-example.jsx View on Github external
return val => {
        if (val && val.target) // in case we got a `SyntheticEvent` object; react-widgets pass the value directly to onChange
          val = val.target.value

        setter(path)(this.state, val)
        this.setState(this.state, () => this._runValidations())
      }
    }
github jquense / yup / src / util / reach.js View on Github external
export function getIn(schema, path, value, context) {
  let parent, lastPart, lastPartDebug;

  // if only one "value" arg then use it for both
  context = context || value;

  if (!path)
    return {
      parent,
      parentPath: path,
      schema,
    };

  forEach(path, (_part, isBracket, isArray) => {
    let part = isBracket ? trim(_part) : _part;

    if (isArray || has(schema, '_subType')) {
      // we skipped an array: foo[].bar
      let idx = isArray ? parseInt(part, 10) : 0;

      schema = schema.resolve({ context, parent, value })._subType;

      if (value) {
        if (isArray && idx >= value.length) {
          throw new Error(
            `Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` +
              `because there is no value at that index. `,
          );
        }
github jquense / react-formal / src / utils / paths.js View on Github external
export function inPath(basePath, childPath) {
  if (basePath === childPath) return true

  var partsA = prop.split(basePath) || []
    , partsB = prop.split(childPath) || []

  if (partsA.length > partsB.length)
    return false

  return partsA.every(
    (part, idx) => clean(part) === clean(partsB[idx]))
}
github jquense / react-formal / src / util / update.js View on Github external
module.exports = function update(model, path, value) {
  var parts = prop.split(path)
    , newModel = copy(model)
    , part, islast;

  if ( newModel === undefined )
    newModel = IS_ARRAY.test(parts[0]) ? [] : {}

  var current = newModel

  for (var idx = 0; idx < parts.length; idx++) {
    islast = idx === (parts.length - 1)
    part = paths.clean(parts[idx])

    if ( islast )
      current[part] = value
    
    else {
github jquense / yup / lib / object.js View on Github external
fields[key]._deps && fields[key]._deps.forEach(function (node) {
      //eslint-disable-line no-loop-func
      node = split(node)[0];

      if (! ~nodes.indexOf(node)) nodes.push(node);

      if (! ~excludes.indexOf('' + key + '-' + node)) edges.push([key, node]);
    });
  }
github jquense / topeka / src / updateIn.js View on Github external
export default function update(model, path, value) {
  var parts = prop.split(path)
    , newModel = copy(model)
    , part, islast;

  if (newModel == null)
    newModel = IS_ARRAY.test(parts[0]) ? [] : {}

  var current = newModel

  for (var idx = 0; idx < parts.length; idx++) {
    islast = idx === (parts.length - 1)
    part = clean(parts[idx])

    if (islast)
      current[part] = value

    else {
github jquense / yup / src / util / sortFields.js View on Github external
function addNode(depPath, key) {
    var node = split(depPath)[0];

    if (!~nodes.indexOf(node)) nodes.push(node);

    if (!~excludes.indexOf(`${key}-${node}`)) edges.push([key, node]);
  }

property-expr

tiny util for getting and setting deep object props safely

MIT
Latest version published 6 months ago

Package Health Score

72 / 100
Full package analysis