ig-types 6.9.5 → 6.11.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/Promise.js CHANGED
@@ -417,6 +417,58 @@ object.Constructor('CooperativePromise', Promise, {
417
417
 
418
418
  //---------------------------------------------------------------------
419
419
 
420
+ var ProxyPromise =
421
+ module.ProxyPromise =
422
+ object.Constructor('ProxyPromise', Promise, {
423
+ __new__: function(context, constructor){
424
+ var proto = 'prototype' in constructor ?
425
+ constructor.prototype
426
+ : constructor
427
+ var obj = Reflect.construct(
428
+ ProxyPromise.__proto__,
429
+ [function(resolve, reject){
430
+ context.then(resolve)
431
+ context.catch(reject) }],
432
+ ProxyPromise)
433
+ // populate...
434
+ // NOTE: we are not using object.deepKeys(..) here as we need
435
+ // the key origin not to trigger property getters...
436
+ var seen = new Set()
437
+ while(proto != null){
438
+ Object.entries(Object.getOwnPropertyDescriptors(proto))
439
+ .forEach(function([key, value]){
440
+ // skip overloaded keys...
441
+ if(seen.has(key)){
442
+ return }
443
+ // skip non-functions...
444
+ if(typeof(value.value) != 'function'){
445
+ return }
446
+ // skip non-enumerable except for Object.prototype.run(..)...
447
+ if(!(key == 'run'
448
+ && Object.prototype.run === value.value)
449
+ && !value.enumerable){
450
+ return }
451
+ // proxy...
452
+ obj[key] = function(...args){
453
+ // XXX should we also .catch(..) here???
454
+ return context.then(function(res){
455
+ return res[key](...args) }) } })
456
+ proto = proto.__proto__ }
457
+ return obj },
458
+ })
459
+
460
+
461
+
462
+ //---------------------------------------------------------------------
463
+
464
+ // XXX EXPEREMENTAL...
465
+ var PromiseProtoMixin =
466
+ module.PromiseProtoMixin =
467
+ object.Mixin('PromiseProtoMixin', 'soft', {
468
+ as: ProxyPromise,
469
+ })
470
+
471
+
420
472
  var PromiseMixin =
421
473
  module.PromiseMixin =
422
474
  object.Mixin('PromiseMixin', 'soft', {
@@ -425,9 +477,11 @@ object.Mixin('PromiseMixin', 'soft', {
425
477
  cooperative: CooperativePromise,
426
478
  })
427
479
 
428
-
429
480
  PromiseMixin(Promise)
430
481
 
482
+ // XXX EXPEREMENTAL...
483
+ PromiseProtoMixin(Promise.prototype)
484
+
431
485
 
432
486
 
433
487
 
package/README.md CHANGED
@@ -74,6 +74,9 @@ Library of JavaScript type extensions, types and utilities.
74
74
  - [`<promise-iter>.flat(..)`](#promise-iterflat)
75
75
  - [`<promise-iter>.then(..)` / `<promise-iter>.catch(..)` / `<promise-iter>.finally(..)`](#promise-iterthen--promise-itercatch--promise-iterfinally)
76
76
  - [Advanced handler](#advanced-handler)
77
+ - [Promise proxies](#promise-proxies)
78
+ - [`<promise>.as(..)`](#promiseas)
79
+ - [`<promise-proxy>.<method>(..)`](#promise-proxymethod)
77
80
  - [Generator extensions and utilities](#generator-extensions-and-utilities)
78
81
  - [The basics](#the-basics)
79
82
  - [`generator.Generator`](#generatorgenerator)
@@ -1621,6 +1624,56 @@ var p = Promise.iter(
1621
1624
  ```
1622
1625
 
1623
1626
 
1627
+ ### Promise proxies
1628
+
1629
+ _Promise proxies_ generate a set of prototype methods returning promises that when the parent promise is resolved will resolve to a specific method call.
1630
+
1631
+ Example:
1632
+ ```javascript
1633
+ var o = {
1634
+ method: function(...args){
1635
+ console.log('method:', ...args)
1636
+ },
1637
+ }
1638
+
1639
+ var p = Peomise.cooperative().as(o)
1640
+
1641
+ p.method(1, 2, 3) // returns a promise...
1642
+
1643
+ // ...
1644
+
1645
+ // resolving a promise will trigger all the proxy emthod execution, so
1646
+ // here 'method: 1, 2, 3' will get printed...
1647
+ p.set(o)
1648
+
1649
+ ```
1650
+
1651
+ #### `<promise>.as(..)`
1652
+
1653
+ Create a promise proxy
1654
+
1655
+ ```bnf
1656
+ <promise>.as(<object>)
1657
+ <promise>.as(<constructor>)
1658
+ -> <promise-proxy>
1659
+ ```
1660
+
1661
+ A proxy promise will be populated with proxy methods to all the methods of the `<object>` or `<constructor>.prototype`.
1662
+
1663
+ #### `<promise-proxy>.<method>(..)`
1664
+
1665
+ When `<promise>` resolves, call the `.<method>(..)` on the resolved value.
1666
+
1667
+ ```bnf
1668
+ <promise-proxy>.<method>(..)
1669
+ -> <method-promise>
1670
+ ```
1671
+
1672
+ `<method-promise>` will resolve the the return value of the `<method>` when
1673
+ the main `<promise>` is resolved.
1674
+
1675
+
1676
+
1624
1677
  ## Generator extensions and utilities
1625
1678
 
1626
1679
  ```javascript
package/event.js CHANGED
@@ -34,17 +34,17 @@ module.TRIGGER = module.EventCommand('TRIGGER')
34
34
 
35
35
 
36
36
 
37
- // Create an "eventfull" method...
37
+ // Create an "eventful" method...
38
38
  //
39
39
  // The resulting method can be either called directly or via .trigger(..).
40
40
  // Handlrs can be bound to it via .on(..) and unbound via .off(..) and
41
41
  // calling it will trigger the handlers either after the user func(..)
42
42
  // return or when the user calles the passed handler(..) function.
43
43
  //
44
- // Eventfull(name[, options])
44
+ // Eventful(name[, options])
45
45
  // -> method
46
46
  //
47
- // Eventfull(name, func[, options])
47
+ // Eventful(name, func[, options])
48
48
  // -> method
49
49
  //
50
50
  //
@@ -63,6 +63,11 @@ module.TRIGGER = module.EventCommand('TRIGGER')
63
63
  // -> true
64
64
  // -> false
65
65
  //
66
+ // trigger event handlers and overload handler arguments...
67
+ // handle(true, ...)
68
+ // -> true
69
+ // -> false
70
+ //
66
71
  // prevent event handlers from triggering...
67
72
  // handle(false)
68
73
  // -> undefined
@@ -88,9 +93,9 @@ module.TRIGGER = module.EventCommand('TRIGGER')
88
93
  //
89
94
  // NOTE: calling handle(false) will exiplicitly disable calling the
90
95
  // handlers for that call...
91
- var Eventfull =
92
- module.Eventfull =
93
- object.Constructor('Eventfull', {
96
+ var Eventful =
97
+ module.Eventful =
98
+ object.Constructor('Eventful', {
94
99
 
95
100
  handlerLocation: 'context',
96
101
 
@@ -151,11 +156,15 @@ object.Constructor('Eventfull', {
151
156
  // NOTE: to explicitly disable calling the handlers func must
152
157
  // call handle(false)
153
158
  var did_handle = false
154
- var handle = function(run=true){
159
+ var handle = function(run=true, ...alt_args){
155
160
  did_handle = true
156
- var a = args[0] instanceof EventCommand ?
157
- args.slice(1)
161
+ var a = (run === true
162
+ && arguments.length > 1) ?
163
+ alt_args
158
164
  : args
165
+ a = a[0] instanceof EventCommand ?
166
+ a.slice(1)
167
+ : a
159
168
  return run ?
160
169
  handlers
161
170
  .reduce(function(res, handler){
@@ -189,7 +198,7 @@ object.Constructor('Eventfull', {
189
198
  })
190
199
 
191
200
 
192
- // Extends Eventfull(..) adding ability to bind events via the
201
+ // Extends Eventful(..) adding ability to bind events via the
193
202
  // resulting method directly by passing it a function...
194
203
  //
195
204
  // Event(name[, options])
@@ -225,7 +234,7 @@ object.Constructor('Eventfull', {
225
234
  // arg is a function or not...
226
235
  var Event =
227
236
  module.Event =
228
- object.Constructor('Event', Eventfull, {
237
+ object.Constructor('Event', Eventful, {
229
238
  toString: function(){
230
239
  return this.orig_func ?
231
240
  'Event '
@@ -241,7 +250,7 @@ object.Constructor('Event', Eventfull, {
241
250
  // call the action...
242
251
  : object.parentCall(Event.prototype.__call__, this, context, ...args)
243
252
  // XXX workaround for above line -- remove when fully tested...
244
- //: Eventfull.prototype.__call__.call(this, context, ...args)
253
+ //: Eventful.prototype.__call__.call(this, context, ...args)
245
254
  return context },
246
255
  })
247
256
 
@@ -330,13 +339,13 @@ module.EventHandlerMixin = object.Mixin('EventHandlerMixin', {
330
339
  // instead...
331
340
  var EventDocMixin =
332
341
  module.EventDocMixin = object.Mixin('EventDocMixin', {
333
- get eventfull(){
342
+ get eventful(){
334
343
  return object.deepKeys(this)
335
344
  .filter(function(n){
336
345
  // avoid triggering props...
337
346
  return !object.values(this, n, function(){ return object.STOP }, true)[0].get
338
347
  // XXX this is too strict...
339
- && (this[n] || {}).constructor === Eventfull}.bind(this)) },
348
+ && (this[n] || {}).constructor === Eventful}.bind(this)) },
340
349
  get events(){
341
350
  return object.deepKeys(this)
342
351
  .filter(function(n){
package/main.js CHANGED
@@ -32,6 +32,7 @@ module.STOP = object.STOP
32
32
 
33
33
  // frequently used stuff...
34
34
  module.Generator = module.generator.Generator
35
+ // XXX doc...
35
36
  module.iter = module.generator.iter
36
37
 
37
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.9.5",
3
+ "version": "6.11.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -381,19 +381,19 @@ Events.cases({
381
381
 
382
382
  // blank events...
383
383
  bareEventBlank: assert(
384
- events.Eventfull('bareEventBlank'),
385
- '.Eventfull(..): blank'),
384
+ events.Eventful('bareEventBlank'),
385
+ '.Eventful(..): blank'),
386
386
  eventBlank: assert(
387
387
  events.Event('eventBlank'),
388
388
  '.Event(..): blank'),
389
389
 
390
390
  // normal events...
391
- bareEvent: assert(events.Eventfull('bareEvent',
391
+ bareEvent: assert(events.Eventful('bareEvent',
392
392
  function(handle, ...args){
393
393
  called['bareEvent-call'] = true
394
- assert(handle(), '.Eventfull(..) -> handle(..)')
394
+ assert(handle(), '.Eventful(..) -> handle(..)')
395
395
  return 'bareEvent'
396
- }), '.Eventfull(..)'),
396
+ }), '.Eventful(..)'),
397
397
  event: assert(events.Event('event',
398
398
  function(handle, ...args){
399
399
  called['event-call'] = true
@@ -408,7 +408,7 @@ Events.cases({
408
408
 
409
409
  // test event list...
410
410
  assert.array(obj.events, ['event', 'eventBlank'], '.events')
411
- assert.array(obj.eventfull, ['bareEvent', 'bareEventBlank'], '.eventfull')
411
+ assert.array(obj.eventful, ['bareEvent', 'bareEventBlank'], '.eventful')
412
412
 
413
413
  // bind...
414
414
  var bind = function(evt){
@@ -418,7 +418,7 @@ Events.cases({
418
418
 
419
419
  ;['moo',
420
420
  ...obj.events,
421
- ...obj.eventfull]
421
+ ...obj.eventful]
422
422
  .forEach(bind)
423
423
 
424
424
  assert(obj.event(function(evt, ...args){