How to use the timm.updateIn function in timm

To help you get started, we’ve selected a few timm 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 guigrpa / storyboard / packages / storyboard-extension-chrome / src / reducers / storiesReducer.js View on Github external
} else {
    const { parents } = record;
    if (parents != null && parents.length) {
      let parentStoryId = _.find(parents, (o) => o[0] === 'c');
      if (parentStoryId == null) parentStoryId = parents[0];
      pathStr = openStories[parentStoryId];
      if (pathStr == null && fPastRecords) pathStr = state.closedStories[parentStoryId];
    }
    if (pathStr == null) pathStr = mainStoryPathStr(fServer);
    [state, newStoryPathStr] = addStory(state, pathStr, record, options);
    state = addLog(state, newStoryPathStr, record, options).state;
    rootStoryIdx = newStoryPathStr.split('/')[1];
  }

  // Increment counter
  state = timm.updateIn(state, ['mainStory', 'records', rootStoryIdx, 'numRecords'],
    (o) => o + 1);

  // We return the new state, as well as the path of the new story (if any)
  return [state, newStoryPathStr];
};
github guigrpa / storyboard / packages / storyboard-extension-chrome / src / reducers / storiesReducer.js View on Github external
const addLog = (state0, pathStr, record0, options) => {
  let state = state0;
  let record = record0;
  const { fPastRecords, fExpandAllNewAttachments, fShorthandForDuplicates = true } = options;
  const path = `mainStory/${pathStr}/records`.split('/');
  record = timm.set(record, 'objExpanded', !!fExpandAllNewAttachments);
  let fDuplicate = false;
  let nextRecords;
  state = timm.updateIn(state, path, (prevRecords) => {
    // Handle duplicates when including past records
    if (fPastRecords) {
      const { storyId, id } = record;
      if (_.find(prevRecords, (o) => o.storyId === storyId && o.id === id)) {
        return prevRecords;
      }
    }

    // Handle consecutive repetitions
    if (fShorthandForDuplicates && !record.fStory) {
      const idx = prevRecords.length - 1;
      const prevLastRecord = prevRecords[idx];
      if (prevLastRecord != null &&
        prevLastRecord.msg === record.msg &&
        prevLastRecord.src === record.src &&
        _.isEqual(prevLastRecord.obj, record.obj)
github guigrpa / storyboard / packages / storyboard-extension-chrome / src / reducers / storiesReducer.js View on Github external
if (action.type === 'CLEAR_LOGS') return buildInitialState();

  if (action.type === 'RECORDS_RECEIVED') return rxRecords(state, action, settings);

  if (action.type === 'FORGET') return forgetRecords(state, action, settings);

  if (action.type === 'TOGGLE_EXPANDED') {
    if (action.pathStr == null) return state;
    const path = (`mainStory/${action.pathStr}/fExpanded`).split('/');
    return timm.updateIn(state, path, (fExpanded) => !fExpanded);
  }

  if (action.type === 'TOGGLE_HIERARCHICAL') {
    if (action.pathStr == null) return state;
    const path = (`mainStory/${action.pathStr}/fHierarchical`).split('/');
    return timm.updateIn(state, path, (fHierarchical) => !fHierarchical);
  }

  if (action.type === 'TOGGLE_ATTACHMENT') {
    let { pathStr } = action;
    const { recordId } = action;
    if (pathStr == null || recordId == null) return state;
    pathStr = `mainStory/${pathStr}`;
    const story = timm.getIn(state, pathStr.split('/'));
    if (story == null) return state;
    const recordPathStr = findRecord(story, recordId, !story.fHierarchical, pathStr);
    if (recordPathStr == null) return state;
    const recordPath = recordPathStr.split('/');
    const record = timm.getIn(state, recordPath);
    recordPath.push('objExpanded');
    return timm.setIn(state, recordPath, !record.objExpanded);
  }
github guigrpa / storyboard / packages / storyboard-extension-chrome / src / reducers / storiesReducer.js View on Github external
const rxLog = (state0, record, options) => {
  let state = state0;
  const { localHubId } = state;
  const { storyId, fServer, hubId } = record;
  const { fDiscardRemoteClientLogs } = options;
  if (fDiscardRemoteClientLogs && (!fServer) && hubId !== localHubId) return state;
  const pathStr = state.openStories[storyId] != null
    ? state.openStories[storyId]
    : mainStoryPathStr(fServer);
  const { state: tmpState, fDuplicate } = addLog(state, pathStr, record, options);
  state = tmpState;
  if (!fDuplicate) {
    const rootStoryIdx = pathStr.split('/')[1];
    state = timm.updateIn(state, ['mainStory', 'records', rootStoryIdx, 'numRecords'],
      (o) => o + 1);
  }
  return state;
};