How to use the mobx.isObservableArray function in mobx

To help you get started, we’ve selected a few mobx 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 chameleon-team / chameleon-runtime / test / .chameleon / web / src / platform / common / proto / WexRuntimeCore.js View on Github external
function dataExprFn() {
      oldVal = curVal
      curVal = exprType === 'string' ? getByPath(context, expr) : expr.call(context)
      if (handler.deep) {
        curVal = toJS(curVal, false)
      } else if (isObservableArray(curVal)) {
        // 强制访问,让数组被观察
        curVal.peek()
      }
      return curVal
    }
github be-fe / react-mobx-vm / src / decorator / utils / getStateLifeDecorator.js View on Github external
self[property] = value
      }
    }

    if (typeof val !== 'undefined') {
      logger.debug('before load `' + property + '`:', self[property])
      if (val == null) {
        setVal()
      }
      else if (typeof self[property] === 'object' && self[property] !== null) {
        if (typeof val === 'object') {
          // remove overflow items if arrays
          if (
            Array.isArray(val) &&
            (
              isObservableArray(self[property]) || Array.isArray(self[property])
            )
            && val.length < self[property].length
          ) {
            self[property].splice(val.length, self[property].length - val.length)
          }
          if (Array.isArray(val)) {
            val.forEach((v, k) => assignState(self[property], k, v))
          }
          else {
            for (let k in val) {
              if (val.hasOwnProperty(k)) {
                assignState(self[property], k, val[k])
              }
            }
          }
        }
github mobxjs / mobx-utils / src / chunk-processor.ts View on Github external
export function chunkProcessor(
    observableArray: T[],
    processor: (item: T[]) => void,
    debounce = 0,
    maxChunkSize = 0
): IDisposer {
    if (!isObservableArray(observableArray))
        throw new Error("Expected observable array as first argument")
    if (!isAction(processor)) processor = action("chunkProcessor", processor)

    const runner = () => {
        while (observableArray.length > 0) {
            let chunkSize =
                maxChunkSize === 0
                    ? observableArray.length
                    : Math.min(observableArray.length, maxChunkSize)
            // construct a final set
            const items = observableArray.slice(0, chunkSize)
            // clear the slice for next iteration
            runInAction(() => observableArray.splice(0, chunkSize))
            // fire processor
            processor(items)
        }
github chameleon-team / chameleon-runtime / test / .chameleon / baidu / src / platform / common / util / toJS.js View on Github external
}

  if (detectCycles && __alreadySeen === null) {
    __alreadySeen = []
  }

  if (detectCycles && source !== null && typeof source === "object") {
      for (let i = 0, l = __alreadySeen.length; i < l; i++) {
        if (__alreadySeen[i][0] === source) {
          return __alreadySeen[i][1];
        }
      }
  }
      
  if (isObservable(source)) {
      if (isObservableArray(source)) {
          var res = cache([]);
          var toAdd = source.map(function (value) { return toJS(value, detectCycles, __alreadySeen); });
          res.length = toAdd.length;
          for (var i = 0, l = toAdd.length; i < l; i++)
              res[i] = toAdd[i];
          return res;
      }
      if (isObservableObject(source)) {
          var res = cache({});
          for (var key in source)
              res[key] = toJS(source[key], detectCycles, __alreadySeen);
          return res;
      }
      if (isObservableMap(source)) {
          var res_1 = cache({});
          source.forEach(function (value, key) { return (res_1[key] = toJS(value, detectCycles, __alreadySeen)); });
github nightwolfz / mobx-starter / core / helpers / merge.js View on Github external
Object.keys(target).forEach(key => {
        if (typeof target[key] === 'object') {
            if (isObservableMap(target[key])) return target[key].merge(source[key])
            if (isObservableArray(target[key])) return target[key].replace(source[key])
            extendObservable(target[key], source[key])
        } else {
            target[key] = source[key]
        }
    })
    window.__STATE = target
github nightwolfz / inferno-starter / core / globals.js View on Github external
global.size = function size(input) {
  if (isObservableArray(input) || typeof input === 'string') {
    return input.length
  }
  return input && ((typeof input === 'string') ? input.length : Object.keys(input).length)
}
github jenkinsci / blueocean-plugin / blueocean-pipeline-editor / src / main / js / services / PipelineValidator.js View on Github external
function _isArray(o) {
    return o instanceof Array || typeof o === 'array' || isObservableArray(o);
}
github giladv / orkan / src / orkan / form / observable-nested-map.js View on Github external
return arr.map(value => {
		if(isPlainObject(value) || isObservableObject(value)){
			return nestedMapFromObj(value);
		}else if(isArray(value) || isObservableArray(value)){
			return nestedMapFromArray(value);
		}else if(isObject(value) && !isPlainObject(value)){
			return observable.ref(value);
		}else{
			return value;
		}
	});
}
github poanetwork / token-wizard / src / components / stepFour / index.js View on Github external
downloadCrowdsaleInfo = () => {
    const zip = new JSZip()
    const { files } = FILE_CONTENTS
    const [NULL_FINALIZE_AGENT, FINALIZE_AGENT] = ['nullFinalizeAgent', 'finalizeAgent']
    const tiersCount = isObservableArray(this.props.tierStore.tiers) ? this.props.tierStore.tiers.length : 1
    const contractsKeys = tiersCount === 1 ? files.order.filter(c => c !== NULL_FINALIZE_AGENT) : files.order;
    const orderNumber = order => order.toString().padStart(3, '0');
    let prefix = 1

    contractsKeys.forEach(key => {
      if (this.props.contractStore.hasOwnProperty(key)) {
        const { txt, sol, name } = files[key]
        const { abiConstructor } = this.props.contractStore[key]
        let tiersCountPerContract = isObservableArray(abiConstructor) ? abiConstructor.length : 1

        if (tiersCount > 1 && [NULL_FINALIZE_AGENT, FINALIZE_AGENT].includes(key)) {
          tiersCountPerContract = NULL_FINALIZE_AGENT === key ? tiersCount - 1 : 1
        }

        for (let tier = 0; tier < tiersCountPerContract; tier++) {
          const suffix = tiersCountPerContract > 1 ? `_${tier + 1}` : ''
github sulu / sulu / src / Sulu / Bundle / AdminBundle / Resources / js / services / Requester / Requester.js View on Github external
function transformRequestData(data: Object | Array) {
    if (Array.isArray(data) || isObservableArray(data)) {
        return transformRequestArray(data);
    }

    return transformRequestObject(data);
}