ProposedChangesCollection
A set of proposed changes for one or multiple documents. Keeps and manages these changes' current state.
The changes inside one set are logically related and can be thought as one "review". They are a result of one "processing cycle": one set of changes, all proposed together at once, for one or multiple documents, to be reviewed and accepted or rejected.
The proposed changes are given an index and are addressed by their index in the set. A change never leaves the set, and its index does not change. An accepted or rejected change is still kept in the set at its original index, and can be rendered for preview purposes.
Create the set from the proposed changes, then pass it to create a controller, which binds the set with related editor instance(s) and optionally a view component. Read the set directly, but modify it through the controller API.
The set is owned by the integrator and outlives the controller. It can be passed to a new controller, for example to keep the review when the controller is re-created for a new editor instance. A set must be bound with one controller at a time.
Methods
constructor( changes )module:ai/toolkit/proposedchangescollection~ProposedChangesCollection#constructorParameters
changes: Array<DocumentChange & object>The changes to review, in the order they should be reviewed in. A change may state its decision, to restore a review. Defaults to
'pending'.Defaults to
[]
delegate( events ) → EmitterMixinDelegateChaininheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#delegateDelegates selected events to another
Emitter. For instance:
Copy codeemitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );then
eventXis delegated (fired by)emitterBandemitterCalong withdata:
Copy codeemitterA.fire( 'eventX', data );and
eventYis delegated (fired by)emitterCalong withdata:
Copy codeemitterA.fire( 'eventY', data );Parameters
events: Array<string>Event names that will be delegated to another emitter.
Returns
fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#fireFires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfoobject, followed by the optionalargsprovided in thefire()method call.Type parameters
Parameters
eventOrInfo: GetNameOrEventInfo<TEvent>The name of the event or
EventInfoobject if event is delegated.args: TEvent[ 'args' ]Additional arguments to be passed to the callbacks.
Returns
GetEventInfo<TEvent>[ 'return' ]By default the method returns
undefined. However, the return value can be changed by listeners through modification of theevt.return's property (the event info is the first param of every callback).
getActionableSibling( index, direction ) → number | nullmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#getActionableSiblingThe position of the nearest actionable change in the given direction, or
nullwhen there is none.It is cyclic: "next" from the last change is the first one.
nullis returned only once there are no actionable changes in the set.Parameters
index: numberThe index to step away from.
direction: 'next' | 'previous'Which way to step.
Returns
number | null
getChange( index ) → ProposedChange | undefinedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#getChangeReturns the proposed change at
index, orundefinedwhen the set holds none there.Parameters
index: number
Returns
ProposedChange | undefined
getChanges() → readonly Array<ProposedChange>module:ai/toolkit/proposedchangescollection~ProposedChangesCollection#getChangeshasWritableChanges() → booleanmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#hasWritableChangesWhether there is any writable ("applicable") change in the collection.
Returns
boolean
isActionable( index ) → booleanmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#isActionableWhether the user can make an action (accept or reject) for the change at
index.Actionable change must be in pending state (not accepted or rejected yet), it must yield actual change, it cannot be outdated (the related content must not be removed), and the related document must be available.
If the change affects a read-only content, it is still actionable. Such a change cannot be accepted, but it can be rejected.
An actionable change that can still be accepted is writeable.
Parameters
index: number
Returns
boolean
isWritable( index ) → booleanmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#isWritableWhether the change at
indexcan be accepted by the user.It must be actionable and affect content that is not read-only.
Parameters
index: number
Returns
boolean
listenTo( emitter, event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#listenTo:BASE_EMITTERRegisters a callback function to be executed when an event is fired in a specific (emitter) object.
Events can be grouped in namespaces using
:. When namespaced event is fired, it additionally fires all callbacks for that namespace.
Copy code// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ). myEmitter.on( 'myGroup', genericCallback ); myEmitter.on( 'myGroup:myEvent', specificCallback ); // genericCallback is fired. myEmitter.fire( 'myGroup' ); // both genericCallback and specificCallback are fired. myEmitter.fire( 'myGroup:myEvent' ); // genericCallback is fired even though there are no callbacks for "foo". myEmitter.fire( 'myGroup:foo' );An event callback can stop the event and set the return value of the
firemethod.Type parameters
Parameters
emitter: EmitterThe object that fires the event.
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
off( event, callback ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#offStops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback ).Parameters
event: stringThe name of the event.
callback: FunctionThe function to stop being called.
Returns
void
on( event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#onRegisters a callback function to be executed when an event is fired.
Shorthand for
this.listenTo( this, event, callback, options )(it makes the emitter listen on itself).Type parameters
Parameters
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
once( event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#onceRegisters a callback function to be executed on the next time the event is fired only. This is similar to calling
onfollowed byoffin the callback.Type parameters
Parameters
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
stopDelegating( event?, emitter? ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#stopDelegatingStops delegating events. It can be used at different levels:
- To stop delegating all events.
- To stop delegating a specific event to all emitters.
- To stop delegating a specific event to a specific emitter.
Parameters
event?: stringThe name of the event to stop delegating. If omitted, stops it all delegations.
emitter?: Emitter(requires
event) The object to stop delegating a particular event to. If omitted, stops delegation ofeventto all emitters.
Returns
void
stopListening( emitter?, event?, callback? ) → voidinheritedmodule:ai/toolkit/proposedchangescollection~ProposedChangesCollection#stopListening:BASE_STOPStops listening for events. It can be used at different levels:
- To stop listening to a specific callback.
- To stop listening to a specific event.
- To stop listening to all events fired by a specific object.
- To stop listening to all events fired by all objects.
Parameters
emitter?: EmitterThe object to stop listening to. If omitted, stops it for all objects.
event?: string(Requires the
emitter) The name of the event to stop listening to. If omitted, stops it for all events fromemitter.callback?: Function(Requires the
event) The function to be removed from the call list for the givenevent.
Returns
void
Events
changeUpdated( eventInfo, <anonymous> = { <anonymous>.change, <anonymous>.index } )module:ai/toolkit/proposedchangescollection~ProposedChangesCollection#event:changeUpdatedFired whenever anything about a proposed change state changes.
Parameters
eventInfo: EventInfoAn object containing information about the fired event.
<anonymous>: object- Properties
<anonymous>.change: ProposedChange<anonymous>.index: number