ig-types 6.20.3 → 6.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Date.js +9 -0
- package/README.md +160 -13
- package/event.js +1 -1
- package/package.json +1 -1
package/Date.js
CHANGED
|
@@ -15,6 +15,15 @@ var object = require('ig-object')
|
|
|
15
15
|
var DateMixin =
|
|
16
16
|
module.DateMixin =
|
|
17
17
|
object.Mixin('DateMixin', 'soft', {
|
|
18
|
+
hires: function(){
|
|
19
|
+
return typeof(process) != 'undefined' ?
|
|
20
|
+
performance.timeOrigin + performance.now()
|
|
21
|
+
: performance.timing.navigationStart + performance.now() },
|
|
22
|
+
hiresTimeStamp: function(){
|
|
23
|
+
var t = this.hires()
|
|
24
|
+
var date = new this(t)
|
|
25
|
+
return date.getTimeStamp(true) + (''+(t-date.getTime())).slice(1) },
|
|
26
|
+
|
|
18
27
|
timeStamp: function(...args){
|
|
19
28
|
return (new this()).getTimeStamp(...args) },
|
|
20
29
|
fromTimeStamp: function(ts){
|
package/README.md
CHANGED
|
@@ -160,6 +160,7 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
160
160
|
- [Event](#event)
|
|
161
161
|
- [`event.Eventfull(..)`](#eventeventfull)
|
|
162
162
|
- [`event.Event(..)`](#eventevent)
|
|
163
|
+
- [`event.PureEvent(..)`](#eventpureevent)
|
|
163
164
|
- [`event.TRIGGER`](#eventtrigger)
|
|
164
165
|
- [`event.EventHandlerMixin`](#eventeventhandlermixin)
|
|
165
166
|
- [`<obj>.on(..)`](#objon)
|
|
@@ -2829,6 +2830,9 @@ otherwise [`.unorderedRename(..)`](#unique-key-mapunorderedrename) is called.
|
|
|
2829
2830
|
|
|
2830
2831
|
## Event
|
|
2831
2832
|
|
|
2833
|
+
This module defines a set of pure-JavaScript event-like method constructors
|
|
2834
|
+
and utilities.
|
|
2835
|
+
|
|
2832
2836
|
```javascript
|
|
2833
2837
|
var event = require('ig-types/event')
|
|
2834
2838
|
```
|
|
@@ -2836,60 +2840,199 @@ var event = require('ig-types/event')
|
|
|
2836
2840
|
|
|
2837
2841
|
### `event.Eventfull(..)`
|
|
2838
2842
|
|
|
2839
|
-
|
|
2843
|
+
Create and eventful method.
|
|
2844
|
+
```dnf
|
|
2845
|
+
event.Eventfull(<name>[, <options>])
|
|
2846
|
+
event.Eventfull(<name>, <func>[, <options>])
|
|
2847
|
+
-> <method>
|
|
2848
|
+
```
|
|
2849
|
+
|
|
2850
|
+
An eventful method is a method that can be called either directly or via
|
|
2851
|
+
`.trigger(<method-name>, ..)`.
|
|
2852
|
+
|
|
2853
|
+
|
|
2854
|
+
Calling an eventful method will call `<func>(..)` if defined and will
|
|
2855
|
+
trigger the eventful method's handlers trigger, either after `<func>(..)`
|
|
2856
|
+
returns or when `<hander>(..)` is called within `<func>(..)`.
|
|
2857
|
+
```dnf
|
|
2858
|
+
<method>(..)
|
|
2859
|
+
-> <value>
|
|
2860
|
+
```
|
|
2861
|
+
|
|
2862
|
+
Note that if `<func>(..)` returns `undefined` then `<method>(..)` will
|
|
2863
|
+
return either `this` or `undefined` depending on `<options>.defaultReturn`
|
|
2864
|
+
being set to `'context'` (default) or `undefined` resp.
|
|
2865
|
+
|
|
2866
|
+
|
|
2867
|
+
Handlers can be bound to an eventful method via `.on(<method-name>, ...)`,
|
|
2868
|
+
unbound via `.off(<method-name>)`,
|
|
2869
|
+
see: [`event.EventHandlerMixin`](#eventeventhandlermixin) for more info.
|
|
2870
|
+
|
|
2871
|
+
```dnf
|
|
2872
|
+
<handler>(<event-name>, ...)
|
|
2873
|
+
```
|
|
2874
|
+
|
|
2875
|
+
|
|
2876
|
+
The event `<func>(..)` gets the `<handle-func>(..)` as first argument
|
|
2877
|
+
followed by the arguments passed to `<method>(..)` when called.
|
|
2878
|
+
```dnf
|
|
2879
|
+
<func>(<handle-func>, ...)
|
|
2880
|
+
-> <value>
|
|
2881
|
+
```
|
|
2882
|
+
|
|
2883
|
+
`<handle-func>(..)` controls when the event handlers are called.
|
|
2884
|
+
```dnf
|
|
2885
|
+
<handle-func>()
|
|
2886
|
+
<handle-func>(true)
|
|
2887
|
+
-> true
|
|
2888
|
+
-> false
|
|
2889
|
+
|
|
2890
|
+
<handle-func>(true, ...)
|
|
2891
|
+
-> true
|
|
2892
|
+
-> false
|
|
2893
|
+
```
|
|
2894
|
+
|
|
2895
|
+
Calling `<handle-func>(..)` is optional, if not called the handlers will
|
|
2896
|
+
get triggered after `<func>(..)` returns.
|
|
2897
|
+
|
|
2898
|
+
|
|
2899
|
+
Passing `false` to `<handle-func>(..)` will prevent the event handlers
|
|
2900
|
+
from being called.
|
|
2901
|
+
```dnf
|
|
2902
|
+
<handle-func>(false)
|
|
2903
|
+
-> undefined
|
|
2904
|
+
```
|
|
2905
|
+
|
|
2906
|
+
Note that for `async` event `<func>(..)` it might be useful to trigger
|
|
2907
|
+
the handlers after the promise resolves, this can be done by first calling
|
|
2908
|
+
`<handle-func>(false)` to prevent the handlers from being triggered as soon
|
|
2909
|
+
as the promise is returned and after an appropriate `await`ing calling
|
|
2910
|
+
`<handle-func>()` to actually trigger the handlers.
|
|
2911
|
+
|
|
2912
|
+
Example:
|
|
2913
|
+
```javascript
|
|
2914
|
+
var evt = event.Event('evt', async function(handler, ...args){
|
|
2915
|
+
handler(false)
|
|
2916
|
+
var value = await something()
|
|
2917
|
+
handler()
|
|
2918
|
+
return value })
|
|
2919
|
+
```
|
|
2920
|
+
|
|
2921
|
+
|
|
2922
|
+
**Special case: `<event-commands>`**
|
|
2923
|
+
|
|
2924
|
+
`<event-command>`s are instances of `EventCommand` that are handled by
|
|
2925
|
+
event methods in a special way.
|
|
2926
|
+
|
|
2927
|
+
```dnf
|
|
2928
|
+
<method>(<event-command>, ...)
|
|
2929
|
+
-> <value>
|
|
2930
|
+
|
|
2931
|
+
<func>(<handle-func>, <event-command>, ...)
|
|
2932
|
+
-> <value>
|
|
2933
|
+
```
|
|
2934
|
+
|
|
2935
|
+
`EventCommand` instance can be passed as the first argument of `<method>(..)`,
|
|
2936
|
+
in this case the event function will get it but the event handlers
|
|
2937
|
+
will not.
|
|
2938
|
+
|
|
2939
|
+
This is done to be able to externally pass commands to event methods
|
|
2940
|
+
that get handled in a special way by the function but not passed to
|
|
2941
|
+
the event handlers.
|
|
2942
|
+
|
|
2943
|
+
For an example of a built-in `<event-command>` see: [`event.TRIGGER`](#eventtrigger)
|
|
2944
|
+
|
|
2840
2945
|
|
|
2841
2946
|
|
|
2842
2947
|
### `event.Event(..)`
|
|
2843
2948
|
|
|
2844
|
-
|
|
2949
|
+
Extends `Eventful(..)` adding ability to bind events via the resulting
|
|
2950
|
+
method directly by passing it a function.
|
|
2951
|
+
|
|
2952
|
+
```dnf
|
|
2953
|
+
<method>(<handler>)
|
|
2954
|
+
-> <this>
|
|
2955
|
+
```
|
|
2956
|
+
|
|
2957
|
+
|
|
2958
|
+
### `event.PureEvent(..)`
|
|
2959
|
+
|
|
2960
|
+
Like `Event(..)` but produces an event method that can only be triggered
|
|
2961
|
+
via .trigger(name, ...), calling this is a no-op.
|
|
2962
|
+
|
|
2845
2963
|
|
|
2846
2964
|
|
|
2847
2965
|
### `event.TRIGGER`
|
|
2848
2966
|
|
|
2849
|
-
|
|
2967
|
+
Special value (`<event-command>`) that when passed to an event method as
|
|
2968
|
+
first argument will force it to trigger event if the first argument was
|
|
2969
|
+
a function.
|
|
2850
2970
|
|
|
2851
2971
|
|
|
2852
|
-
Special value when passed to an event method as first argument will force it
|
|
2853
|
-
to trigger event if the first argument was a function.
|
|
2854
2972
|
|
|
2855
2973
|
### `event.EventHandlerMixin`
|
|
2856
2974
|
|
|
2857
|
-
|
|
2975
|
+
A _mixin_ defining the basic event API.
|
|
2976
|
+
|
|
2977
|
+
For more info on mixins see:
|
|
2978
|
+
https://github.com/flynx/object.js#mixin
|
|
2858
2979
|
|
|
2859
2980
|
|
|
2860
2981
|
#### `<obj>.on(..)`
|
|
2861
2982
|
|
|
2862
|
-
|
|
2983
|
+
Bind a handler to an _event_ or an _eventful_ method.
|
|
2984
|
+
```dnf
|
|
2985
|
+
<obj>.on(<event-name>, <handler>)
|
|
2986
|
+
-> <obj>
|
|
2987
|
+
```
|
|
2863
2988
|
|
|
2864
2989
|
|
|
2865
2990
|
#### `<obj>.one(..)`
|
|
2866
2991
|
|
|
2867
|
-
|
|
2992
|
+
Like `<obj>.on(..)` but the `<handler>` will be called only once.
|
|
2993
|
+
```dnf
|
|
2994
|
+
<obj>.one(<event-name>, <handler>)
|
|
2995
|
+
-> <obj>
|
|
2996
|
+
```
|
|
2868
2997
|
|
|
2869
2998
|
|
|
2870
2999
|
#### `<obj>.off(..)`
|
|
2871
3000
|
|
|
2872
|
-
|
|
3001
|
+
Unbind `<handler>` from _event_.
|
|
3002
|
+
```dnf
|
|
3003
|
+
<obj>.off(<event-name>, <handler>)
|
|
3004
|
+
-> <obj>
|
|
3005
|
+
```
|
|
2873
3006
|
|
|
2874
3007
|
|
|
2875
3008
|
#### `<obj>.trigger(..)`
|
|
2876
3009
|
|
|
2877
|
-
|
|
3010
|
+
Trigger an _event_.
|
|
3011
|
+
```dnf
|
|
3012
|
+
<obj>.trigger(<event-name>)
|
|
3013
|
+
<obj>.trigger(<event-name>, ...)
|
|
3014
|
+
-> <obj>
|
|
3015
|
+
```
|
|
3016
|
+
|
|
2878
3017
|
|
|
2879
3018
|
|
|
2880
3019
|
### `event.EventDocMixin`
|
|
2881
3020
|
|
|
2882
|
-
|
|
3021
|
+
A _mixin_ defining the basic event introspection API.
|
|
3022
|
+
|
|
3023
|
+
For more info on mixins see:
|
|
3024
|
+
https://github.com/flynx/object.js#mixin
|
|
2883
3025
|
|
|
2884
3026
|
|
|
2885
3027
|
#### `<obj>.eventfull`
|
|
2886
3028
|
|
|
2887
|
-
|
|
3029
|
+
Property listing the _eventful_ method names in the current context.
|
|
2888
3030
|
|
|
2889
3031
|
|
|
2890
3032
|
#### `<obj>.events`
|
|
2891
3033
|
|
|
2892
|
-
|
|
3034
|
+
Property listing the _event_ method names in the current context, this
|
|
3035
|
+
also will include _eventful_ method names.
|
|
2893
3036
|
|
|
2894
3037
|
|
|
2895
3038
|
### `event.EventMixin`
|
|
@@ -2897,6 +3040,10 @@ to trigger event if the first argument was a function.
|
|
|
2897
3040
|
Combines [`event.EventHandlerMixin`](#eventeventhandlermixin) and
|
|
2898
3041
|
[`event.EventDocMixin`](#eventeventdocmixin).
|
|
2899
3042
|
|
|
3043
|
+
For more info on mixins see:
|
|
3044
|
+
https://github.com/flynx/object.js#mixin
|
|
3045
|
+
|
|
3046
|
+
|
|
2900
3047
|
## Runner
|
|
2901
3048
|
|
|
2902
3049
|
```javascript
|
package/event.js
CHANGED
|
@@ -290,7 +290,7 @@ object.Constructor('PureEvent', Event, {
|
|
|
290
290
|
func = undefined }
|
|
291
291
|
object.parentCall(PureEvent.prototype.__init__, this,
|
|
292
292
|
name,
|
|
293
|
-
function(handle, trigger, args){
|
|
293
|
+
function(handle, trigger, ...args){
|
|
294
294
|
trigger === module.TRIGGER ?
|
|
295
295
|
func && func.call(this, handle, ...args)
|
|
296
296
|
: handle(false) }, options) },
|