Gets whether we can redo at this time.
Sets whether we can redo at this time.
Gets whether we can undo at this time.
Sets whether we can undo at this time.
The current history action.
Gets the number of async actions currently executing.
Sets the number of async actions currently executing.
The last action committed to the history.
Gets whether events are suspended.
Sets whether events are suspended. If true, the observer will not emit events when values are set.
Adds a new history action to the stack. If the action has a combine flag and matches the current action's name, the redo function of the current action is updated. If actions have been undone before adding this new action, it removes all actions that come after the current action to maintain a consistent history.
The action to add.
true
if the action is successfully added, false
otherwise.Adds a new history action and immediately executes its redo function.
The action.
A promise that resolves once the redo function has been executed.
Adds another emitter. Any events fired by this instance will also be fired on the additional emitter.
The emitter
Emits the specified event, executing all registered listeners for that event with the provided arguments. If events are suspended, the emit operation will be ignored.
The name of the event to emit.
Optional
arg0: anyThe first argument to pass to the event listeners.
Optional
arg1: anyThe second argument to pass to the event listeners.
Optional
arg2: anyThe third argument to pass to the event listeners.
Optional
arg3: anyThe fourth argument to pass to the event listeners.
Optional
arg4: anyThe fifth argument to pass to the event listeners.
Optional
arg5: anyThe sixth argument to pass to the event listeners.
Optional
arg6: anyThe seventh argument to pass to the event listeners.
Optional
arg7: anyThe eighth argument to pass to the event listeners.
The current instance for chaining.
// Register an event listener
events.on('testEvent', (arg1, arg2) => {
console.log('Event triggered with arguments:', arg1, arg2);
});
// Emit the event
events.emit('testEvent', 'value1', 'value2');
// Emit the event with more arguments
events.emit('testEvent', 'value1', 'value2', 'value3', 'value4');
Registers an event listener for the specified event name. If the event is emitted, the callback function is executed with up to 8 arguments.
The name of the event to listen for.
The callback function to be executed when the event is emitted.
An EventHandle object that can be used to unbind the event listener.
Registers a one-time event listener for the specified event name. The callback function is executed the next time the event is emitted, and then automatically unbound.
The name of the event to listen for.
The callback function to be executed once when the event is emitted.
An EventHandle object that can be used to unbind the event listener before it is triggered.
// Register a one-time event listener
events.once('testEvent', (arg1, arg2) => {
console.log('Event triggered once with arguments:', arg1, arg2);
});
// Emit the event
events.emit('testEvent', 'value1', 'value2'); // The callback will be called and then unbound.
// Emit the event again
events.emit('testEvent', 'value1', 'value2'); // The callback will not be called this time.
Removes emitter.
The emitter
Unbinds an event listener for the specified event name. If a callback function is provided, only that specific listener is removed. If no callback is provided, all listeners for the event are removed. If no event name is provided, all listeners for all events are removed.
Optional
name: stringThe name of the event to unbind. If not provided, all events are unbound.
Optional
fn: HandleEventThe specific callback function to remove. If not provided, all listeners for the event are removed.
The current instance for chaining.
// Register an event listener
const callback = (arg1, arg2) => {
console.log('Event triggered with arguments:', arg1, arg2);
};
events.on('testEvent', callback);
// Unbind the specific event listener
events.unbind('testEvent', callback);
// Unbind all listeners for a specific event
events.unbind('testEvent');
// Unbind all listeners for all events
events.unbind();
Manages history actions for undo/redo operations. This class keeps track of actions that can be undone and redone, allowing for complex state management in applications such as editors, games, or any interactive applications where state changes need to be reversible.
Example