ig-types 6.19.0 → 6.20.2
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/README.md +11 -2
- package/event.js +22 -9
- package/generator.js +23 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,6 +111,7 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
111
111
|
- [`<generator>.shift()` / `<generator>.pop()` / `<generator>.gshift()` / `<generator>.gpop()`](#generatorshift--generatorpop--generatorgshift--generatorgpop)
|
|
112
112
|
- [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush)
|
|
113
113
|
- [`<generator>.join(..)`](#generatorjoin)
|
|
114
|
+
- [`<generator>.unwind(..)`](#generatorunwind)
|
|
114
115
|
- [`<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally)
|
|
115
116
|
- [`<generator>.toArray()`](#generatortoarray)
|
|
116
117
|
- [Treating iterators the same as generators](#treating-iterators-the-same-as-generators)
|
|
@@ -124,7 +125,7 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
124
125
|
- [`<Generator>.between(..)`](#generatorbetween-1)
|
|
125
126
|
- [`<Generator>.toArray()`](#generatortoarray-1)
|
|
126
127
|
- [`<Generator>.join(..)`](#generatorjoin-1)
|
|
127
|
-
- [`<Generator>.
|
|
128
|
+
- [`<Generator>.unwind(..)`](#generatorunwind-1)
|
|
128
129
|
- [Generator combinators](#generator-combinators)
|
|
129
130
|
- [`<Generator>.chain(..)` / `<generator>.chain(..)`](#generatorchain--generatorchain)
|
|
130
131
|
- [`<Generator>.concat(..)` / `<generator>.concat(..)`](#generatorconcat--generatorconcat)
|
|
@@ -136,6 +137,7 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
136
137
|
- [`generator.stoppable(..)`](#generatorstoppable)
|
|
137
138
|
- [Async generator extensions](#async-generator-extensions)
|
|
138
139
|
- [`generator.AsyncGenerator`](#generatorasyncgenerator)
|
|
140
|
+
- [`<async-generator>.unwind(..)`](#async-generatorunwind)
|
|
139
141
|
- [`<async-generator>.then(..)` / `<async-generator>.catch(..)` / `<async-generator>.finally(..)`](#async-generatorthen--async-generatorcatch--async-generatorfinally)
|
|
140
142
|
- [`<async-generator>.iter(..)`](#async-generatoriter)
|
|
141
143
|
- [`<async-generator>.map(..)` / `<async-generator>.filter(..)` / `<async-generator>.reduce(..)`](#async-generatormap--async-generatorfilter--async-generatorreduce)
|
|
@@ -2292,6 +2294,11 @@ _next_ call to `.next()`, regardless of the current generator state.
|
|
|
2292
2294
|
XXX
|
|
2293
2295
|
|
|
2294
2296
|
|
|
2297
|
+
#### `<generator>.unwind(..)`
|
|
2298
|
+
|
|
2299
|
+
XXX
|
|
2300
|
+
|
|
2301
|
+
|
|
2295
2302
|
#### `<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`
|
|
2296
2303
|
|
|
2297
2304
|
Return a promise and resolve it with the generator value.
|
|
@@ -2513,7 +2520,7 @@ Return a function that will return a `<generator>` output as an `Array`.
|
|
|
2513
2520
|
XXX
|
|
2514
2521
|
|
|
2515
2522
|
|
|
2516
|
-
#### `<Generator>.
|
|
2523
|
+
#### `<Generator>.unwind(..)`
|
|
2517
2524
|
|
|
2518
2525
|
<!-- XXX -->
|
|
2519
2526
|
|
|
@@ -2641,6 +2648,8 @@ XXX EXPERIMENTAL
|
|
|
2641
2648
|
|
|
2642
2649
|
#### `generator.AsyncGenerator`
|
|
2643
2650
|
|
|
2651
|
+
#### `<async-generator>.unwind(..)`
|
|
2652
|
+
|
|
2644
2653
|
#### `<async-generator>.then(..)` / `<async-generator>.catch(..)` / `<async-generator>.finally(..)`
|
|
2645
2654
|
|
|
2646
2655
|
#### `<async-generator>.iter(..)`
|
package/event.js
CHANGED
|
@@ -51,6 +51,8 @@ module.TRIGGER = module.EventCommand('TRIGGER')
|
|
|
51
51
|
// Trigger the event...
|
|
52
52
|
// method(...args)
|
|
53
53
|
// -> ..
|
|
54
|
+
// NOTE: if func(..) returns undefined this will return undefined
|
|
55
|
+
// when called without a context and the call context otherwise
|
|
54
56
|
//
|
|
55
57
|
//
|
|
56
58
|
// func(handle, ...args)
|
|
@@ -99,6 +101,14 @@ object.Constructor('Eventful', {
|
|
|
99
101
|
|
|
100
102
|
handlerLocation: 'context',
|
|
101
103
|
|
|
104
|
+
// Sets the default return mode for .__call__(..) if either .func(..)
|
|
105
|
+
// is not set or returns undefined...
|
|
106
|
+
//
|
|
107
|
+
// Can be:
|
|
108
|
+
// 'context'
|
|
109
|
+
// undefined
|
|
110
|
+
defaultReturn: 'context',
|
|
111
|
+
|
|
102
112
|
name: null,
|
|
103
113
|
func: null,
|
|
104
114
|
|
|
@@ -190,7 +200,11 @@ object.Constructor('Eventful', {
|
|
|
190
200
|
// or explicitly called handle(false)...
|
|
191
201
|
!did_handle
|
|
192
202
|
&& handle()
|
|
193
|
-
|
|
203
|
+
|
|
204
|
+
return res
|
|
205
|
+
?? (this.defaultReturn == 'context' ?
|
|
206
|
+
context
|
|
207
|
+
: res ) },
|
|
194
208
|
|
|
195
209
|
__init__: function(name, func, options={}){
|
|
196
210
|
options = func && typeof(func) != 'function' ?
|
|
@@ -251,16 +265,15 @@ object.Constructor('Event', Eventful, {
|
|
|
251
265
|
.replace(/^(function[^(]*\()[^,)]*, ?/, '$1')
|
|
252
266
|
: `Event function ${this.name}(){}`},
|
|
253
267
|
__call__: function(context, ...args){
|
|
268
|
+
// add handler...
|
|
254
269
|
// NOTE: when the first arg is an event command this will
|
|
255
270
|
// fall through to calling the action...
|
|
256
|
-
typeof(args[0]) == 'function'
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//: Eventful.prototype.__call__.call(this, context, ...args)
|
|
263
|
-
return context },
|
|
271
|
+
if(typeof(args[0]) == 'function'){
|
|
272
|
+
this.bind(context, args[0])
|
|
273
|
+
return context
|
|
274
|
+
// call the action...
|
|
275
|
+
} else {
|
|
276
|
+
return object.parentCall(Event.prototype.__call__, this, context, ...args) } },
|
|
264
277
|
})
|
|
265
278
|
|
|
266
279
|
|
package/generator.js
CHANGED
|
@@ -189,11 +189,11 @@ var makeGenerator = function(name, pre){
|
|
|
189
189
|
].join('\n ') }, }) } }
|
|
190
190
|
|
|
191
191
|
// XXX do a better doc...
|
|
192
|
-
var
|
|
192
|
+
var makeProxy = function(name){
|
|
193
193
|
return function(...args){
|
|
194
194
|
var that = this
|
|
195
195
|
return function(){
|
|
196
|
-
return that(...arguments)[name](
|
|
196
|
+
return that(...arguments)[name](...args) } } }
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
@@ -267,9 +267,12 @@ object.Mixin('GeneratorMixin', 'soft', {
|
|
|
267
267
|
|
|
268
268
|
// promises...
|
|
269
269
|
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
// NOTE: .then(..) and friends are intentionally not defined here to
|
|
271
|
+
// prevent control deadlocks when awaiting for a generator that
|
|
272
|
+
// expects manual unwinding e.g.:
|
|
273
|
+
// g = function*(){}
|
|
274
|
+
// await g // will hang waiting for g to resolve
|
|
275
|
+
unwind: makeProxy('unwind'),
|
|
273
276
|
|
|
274
277
|
// combinators...
|
|
275
278
|
//
|
|
@@ -450,7 +453,8 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
|
|
|
450
453
|
|
|
451
454
|
// promises...
|
|
452
455
|
//
|
|
453
|
-
|
|
456
|
+
// NOTE: this will unwind the generator...
|
|
457
|
+
unwind: function(onresolve, onreject){
|
|
454
458
|
var that = this
|
|
455
459
|
var p = new Promise(
|
|
456
460
|
function(resolve){
|
|
@@ -459,10 +463,12 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
|
|
|
459
463
|
p.then(...arguments)
|
|
460
464
|
: p
|
|
461
465
|
return p },
|
|
466
|
+
then: function(...args){
|
|
467
|
+
return this.unwind(...args) },
|
|
462
468
|
catch: function(func){
|
|
463
|
-
return this.
|
|
469
|
+
return this.unwind().catch(...arguments) },
|
|
464
470
|
finally: function(func){
|
|
465
|
-
return this.
|
|
471
|
+
return this.unwind.finally(...arguments) },
|
|
466
472
|
|
|
467
473
|
// combinators...
|
|
468
474
|
//
|
|
@@ -531,22 +537,23 @@ object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
|
|
|
531
537
|
//
|
|
532
538
|
// NOTE: this will unwind the generator...
|
|
533
539
|
// XXX create an iterator promise???
|
|
534
|
-
|
|
535
|
-
then: function(resolve, reject){
|
|
540
|
+
unwind: function(onresolve, onreject){
|
|
536
541
|
var that = this
|
|
537
|
-
var p = new Promise(async function(
|
|
542
|
+
var p = new Promise(async function(resolve){
|
|
538
543
|
var res = []
|
|
539
544
|
for await(var elem of that){
|
|
540
545
|
res.push(elem) }
|
|
541
|
-
|
|
542
|
-
p = (
|
|
546
|
+
resolve(res) })
|
|
547
|
+
p = (onresolve || onreject) ?
|
|
543
548
|
p.then(...arguments)
|
|
544
549
|
: p
|
|
545
550
|
return p },
|
|
551
|
+
then: function(...args){
|
|
552
|
+
return this.unwind(...args) },
|
|
546
553
|
catch: function(func){
|
|
547
|
-
return this.
|
|
548
|
-
finally: function(){
|
|
549
|
-
return this.
|
|
554
|
+
return this.unwind().catch(...arguments) },
|
|
555
|
+
finally: function(func){
|
|
556
|
+
return this.unwind.finally(...arguments) },
|
|
550
557
|
|
|
551
558
|
// XXX might be a good idea to use this approach above...
|
|
552
559
|
iter: stoppable(async function*(handler=undefined){
|