Skip to content

Commit

Permalink
Fix doc strings for model and mutation registry
Browse files Browse the repository at this point in the history
Also:
- simplify the object namespacing used for model.data.confirmed and
  model.data.optimistic
  • Loading branch information
zknill committed Oct 17, 2023
1 parent e816b04 commit 5ecb71a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ export default class Model<T> extends EventEmitter<Record<ModelState, ModelState
return this.currentState;
}

/**
* @returns The an object giving access to the optimistic and confirmed state of the model.
*/
public get data() {
const optimistic = (() => this.optimisticData).bind(this);
const confirmed = (() => this.confirmedData).bind(this);
const self = this;

return {
get optimistic() {
return optimistic();
return self.optimisticData;
},
get confirmed() {
return confirmed();
return self.confirmedData;
},
};
}
Expand Down
10 changes: 0 additions & 10 deletions src/MutationsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ export default class MutationsRegistry {
);
}

/**
* The optimisticEvent function that handles including optimistic events in the model state.
* @param {OptimisticInvocationParams} params - The set of events (params.events) that should be optimistically
* applied to the model state. And optionally a timeout (params.options.timeout) within which a confirmed
* event should be received from the backend, or else the optimistic events will rollback.
* @returns {Promise<[Promise<void>,() => void]>} A Promise that resolves to a [confirmed, cancel] tuple
* when the model has successfully applied the optimistic update. The confirmed field from the tuple is a
* promise that resolves when the optimistic event is confirmed. The cancel field from the tuple is a
* function that can be used to trigger the rollback of the optimistic event.
*/
public async handleOptimsitic(params: OptimisticInvocationParams): Promise<[Promise<void>, () => Promise<void>]> {
const mergedOptions = this.mergeOptions(params.options, this.options, DEFAULT_OPTIONS);

Expand Down

0 comments on commit 5ecb71a

Please sign in to comment.