code: function applyStateChanges(state, changes) {
    let result = false;
  
    // Applying the changes may produce a new round of changes, and that round
    // might produce new changes, and so on. Loop until we complete a pass that
    // produces no changes.
    for (
      let changed;
      changed = fieldsChanged(state, changes), !isEmpty(changed);
    ) {
      // We do have some real changes to report.
      result = true;
  
      // Apply the changes to the state.
      Object.assign(state, changes);
  
      // Run the change handlers, gathering up the changes those produce.
      const nextChanges = {};
      if (state[changeHandlersKey]) {
        state[changeHandlersKey].forEach(handler => {
          const { dependencies, callback } = handler;
          // Does this handler trigger on any of the changes we have?
          const run = dependencies.some(dependency => changed[dependency]);
          if (run) {
            // Yes, run the change handler and collect its changes.
            const handlerChanges = callback(state, changed);
            Object.assign(nextChanges, handlerChanges);
          }
        });
      }
  
      // If the change handlers produced changes, we'll run the loop again.
      changes = nextChanges;
    }
  
    return result;
  }
docs: Destructively apply the indicated changes to the given state, running any registered change handlers. Return true if the supplied changes produced actual changes (i.e., didn't simply duplicate existing field values).