From d5d49de8922623cc6bba3215c4163fc221733bc9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 28 Oct 2022 18:12:01 +0300 Subject: [PATCH] added event docs... Signed-off-by: Alex A. Naanou --- README.md | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7efff44..2381d8c 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Library of JavaScript type extensions, types and utilities. - [Event](#event) - [`event.Eventfull(..)`](#eventeventfull) - [`event.Event(..)`](#eventevent) + - [`event.PureEvent(..)`](#eventpureevent) - [`event.TRIGGER`](#eventtrigger) - [`event.EventHandlerMixin`](#eventeventhandlermixin) - [`.on(..)`](#objon) @@ -2829,6 +2830,9 @@ otherwise [`.unorderedRename(..)`](#unique-key-mapunorderedrename) is called. ## Event +This module defines a set of pure-JavaScript event-like method constructors +and utilities. + ```javascript var event = require('ig-types/event') ``` @@ -2836,25 +2840,122 @@ var event = require('ig-types/event') ### `event.Eventfull(..)` - +Create and eventful method. +```dnf +event.Eventfull([, ]) +event.Eventfull(, [, ]) + -> +``` + +An eventful method is a method that can be called either directly or via +`.trigger(, ..)`. + + +Calling an eventful method will call `(..)` if defined and will +trigger the eventful method's handlers trigger, either after `(..)` +returns or when `(..)` is called within `(..)`. +```dnf +(..) + -> +``` + +Note that if `(..)` returns `undefined` then `(..)` will +return either `this` or `undefined` depending on `.defaultReturn` +being set to `'context'` (default) or `undefined` resp. + + +Handlers can be bound to an eventful method via `.on(, ...)`, +unbound via `.off()`, +see: [`event.EventHandlerMixin`](#eventeventhandlermixin) for more info. + + +The event `(..)` gets the `(..)` as first argument +followed by the arguments passed to `(..)` when called. +```dnf +(, ...) + -> +``` + +`(..)` controls when the event handlers are called. +```dnf +() +(true) + -> true + -> false + +(true, ...) + -> true + -> false +``` + +Calling `(..)` is optional, if not called the handlers will +get triggered after `(..)` returns. + + +Passing `false` to `(..)` will prevent the event handlers +from being called. +```dnf +(false) + -> undefined +``` + + +**Special case: ``** + +``s are instances of `EventCommand` that are handled by +event methods in a special way. + +```dnf +(, ...) + -> + +(, , ...) + -> +``` + +`EventCommand` instance can be passed as the first argument of `(..)`, +in this case the event function will get it but the event handlers +will not. + +This is done to be able to externally pass commands to event methods +that get handled in a special way by the function but not passed to +the event handlers. + +For an example of a built-in `` see: [`event.TRIGGER`](#eventtrigger) + ### `event.Event(..)` - +Extends `Eventful(..)` adding ability to bind events via the resulting +method directly by passing it a function. + +```dnf +() + -> +``` + + +### `event.PureEvent(..)` + +Like `Event(..)` but produces an event method that can only be triggered +via .trigger(name, ...), calling this is a no-op. + ### `event.TRIGGER` - - - Special value when passed to an event method as first argument will force it to trigger event if the first argument was a function. + + ### `event.EventHandlerMixin` - +A _mixin_ defining the basic event API. + +For more info on mixins see: +https://github.com/flynx/object.js#mixin #### `.on(..)` @@ -2877,19 +2978,24 @@ to trigger event if the first argument was a function. + ### `event.EventDocMixin` - +A _mixin_ defining the basic event introspection API. + +For more info on mixins see: +https://github.com/flynx/object.js#mixin #### `.eventfull` - +Property listing the _eventful_ method names in the current context. #### `.events` - +Property listing the _event_ method names in the current context, this +also will include _eventful_ method names. ### `event.EventMixin` @@ -2897,6 +3003,10 @@ to trigger event if the first argument was a function. Combines [`event.EventHandlerMixin`](#eventeventhandlermixin) and [`event.EventDocMixin`](#eventeventdocmixin). +For more info on mixins see: +https://github.com/flynx/object.js#mixin + + ## Runner ```javascript