Cancelable-event
Cancelable,
Prioritized,
Changeable-value Event
The Cancelable module is an event propagation-processing module, inspired by the EventEmitter in Node.JS
and Bukit Plugin in Minecraft
. Licenses are MIT and freely available, and Compatible with your browser via Webpack.
How to install
npm install cancelable-event --save
Advantage
Cancelable Events
Event recipients can decide whether to cancel an event, and the event recipient may or may not run a specific code depending on whether the event is canceled. This allows you to post-evaluation and then run a particular event to see if it is appropriate to run.
Events with priority
Events are forwarded to the recipient according to priority, and the recipient receives the event value first based on priority, and Change the value that will ultimately be delivered to the sender. This allows The resulting value of all events considered to be created without considering all event conditions at the moment.
Traceable Events
Both the process of modifying the event values and the recipient information that determined the event to be aborted are recorded and communicated to the event sender. This allows you to see the event sender function backtrace of the recipient who modified the value unexpectedly and the recipient backtrace that interrupted the event differently. This makes events debugging very easy, considering the fluid situation.
Explanation
When you create a class or variable with Cancelable, an event dispatcher is generated, which allows you to send and receive events. It's divided between the caller and the listener.
Caller
Caller can create event names in a string and then forward the event to the Listeners by putting a value of the desired type as a parameter. Caller receives the final event propagation result value after the value is propagated sequentially to all recipients, It will be contains whether want the event to stop, or whether the event value wants to be changed to a specific value, and the history of the listener changing the value and which listener has stopped the event.
Listener
Listener means a function to receive forwarding when an event occurs. If you want to receive an event when it occurs, you can register the function to receive the event as a callback listener.
Dispatcher
Dispatcher receives events from the sender. It then propagates the event in a priority order to the Listeners who wish to receive it. Dispatcher records how a listener changed the value of an event, both before and after an event value change by the listener, and if the event was interrupted by the listener. Events that have all propagated to the listener are finally passed back to the sender.
Priority
The priority is divided into seven steps, from 0 to 6, and the higher the number, the higher the priority. High priority allows you to receive and process event values first. There are seven steps from the lowest priority 0 to the highest priority 6. Priority can be expressed in numbers immediately, and use by priority name is also possible. The default priority applied is normal = 3
.
var Priority = under: 0 lowest: 1 low: 2 normal: 3 high: 4 highest: 5 monitor: 6
Code Example
Coding examples include creating a dispatcher
and send event
and receiving an event
.
Dispatcher Create Example
Dispatcher can be created by inheriting variables or classes.
Creating Dispatcher with Variables
// ES6let myDispatcher = // ES3var Cancelable = var myDispatcher =
Creating Dispatcher with Class
// ES6 { super // It is absolutely necessary. }let myDispatcher =
Event transmission code
Events can be sent to anyone who has access to Dispatcher.
Simple way to propagate an event
The first parameter must be in the form of a ``string'' and the second parameter is you can be free to choose the type of which you want.
dispatcher
Basic method of event propagation
dispatcher
isCanceled
Indicates whether the event was interrupted. Has a value of theboolean
type.overridedParam
Indicates the last changed event value.traceData
Contains the history of the event value changes and the value of the break history.
Event receiving code
Events can be received by anyone as long as they have access to Dispatcher.
Simple way to receive events
dispatcher
Basic way to receive events
You can prioritize through the third factor of dispatcher.on. ``dispatcher.priority'' or 0-5
numbers can be used as factors, and If you didn't yet prioritize, the normal
will be applied to the priority.
dispatcher
Advanced usage
The Cancelable includes a number of available functions.
How to check the sender's event tracking result
If the event is interrupted, the propagation of the event is stopped immediately and all event traces are conducted through the 'stack-trace' module.
dispatcher
How to check the deep event tracking result of the sender
You can include options in object form in the third parameter of dispatcher.emit
. Trace
and deep
are available as options.
- You can select whether to collect
trace
record change and breaker information. The default option istrue
and tracking information is not collected when applyingfalse
. If you turn off this option, you will naturally not be able to activate thedeep
option. - You can adjust the depth of
deep
trace information collection. When set tofalse
, the source code of the problem or the action is automatically specified. When set totrue
, it returns up to 10 full traces of the problem code execution process. If the deep option is enabled, existing trace objects are returned as an array.
dispatcher
How to receive events asynchronously
WARNING: Asynchronous reception is only available when
non-synchronous receiver is used
is allowed when dispatcher is created.Non-Sync Receiver
is not available in a typical dispatcher, and the method for enabling the use of 'Non-Sync Receiver' is described in the following topics.
You can use this method only if the receiver does not change the event value, does not stop the event, and does not need to know if the event is subsequently canceled. If added as an asynchronous receiver, the value is immediately received asynchronously rather than as a sequence of event values, depending on the priority. When you receive events synchronously, you can take advantage of them for tasks that are expected to experience performance degradation.
dispatcher
How to Set Features to Use when Dispatcher is created
When creating a Dispatcher, you can set options for using a non-synchronous receiver
, value override
, and Restricting Information Collection
.
Creating a Custom Dispatcher through a Variable
// ES6let myDispatcher = async: true // Default: false trace: true // Default: true override: true // Default: true
Creating a Custom Dispatcher through a Class
// ES6 { super async: true // Default: false trace: true // Default: true override: true // Default: true }let myDispatcher =
Development goal
The Cancelable module aims to be compatible with Node.JS EventEmitter.
- Implement cancelable events
- Implementing event value changes based on priority
- Implement event value variation and reverse tracking of canceler information
- Implement object insecurities through Capable Modules
- Implement asynchronous event function
- Complete basic test unit
- Implement object tracking before and after the event value
- Completely support the EventEmitter function
- Add Test Unit
- Add Browser Test Unit
- Add Code Coverage Test Unit
- Re-execute async event function after pre-execution after completion of event
Logo Icon Source
LICENSE
MIT License.