ig-types 6.22.2 → 6.23.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.
Files changed (3) hide show
  1. package/Promise.js +27 -34
  2. package/README.md +15 -0
  3. package/package.json +1 -1
package/Promise.js CHANGED
@@ -795,60 +795,53 @@ object.Constructor('ProxyPromise', Promise, {
795
795
 
796
796
  //---------------------------------------------------------------------
797
797
 
798
+ // XXX EXPEREMENTAL...
799
+ // XXX DOCS...
798
800
  // XXX like promise but if a value can be generated sync then this will
799
801
  // run in sync otherwise it will fall back to being a promise...
800
- // ...not sure where to return the sync value...
801
802
  // XXX potential problem is recursion (depth) on the sync stage...
802
- // XXX not sure if we need this..
803
- var MaybePromice =
804
- module.MaybePromice =
803
+ // XXX should we throw errors in sync mode???
804
+ var MaybePromise =
805
+ module.MaybePromise =
805
806
  object.Constructor('MaybePromise', Promise, {
806
- // XXX can we get into this without either .__error or .__result ???
807
+ //error: undefined,
808
+ //value: undefined,
809
+
807
810
  then: function(resolve, reject){
808
- if(this.hasOwnProperty('__error')){
811
+ if(this.hasOwnProperty('error')){
809
812
  return this.constructor.reject(
810
813
  reject ?
811
- reject(this.__error)
812
- : this.__error) }
813
- if(this.hasOwnProperty('__result')){
814
+ reject(this.error)
815
+ : this.error) }
816
+ if(this.hasOwnProperty('value')){
814
817
  return this.constructor.resolve(
815
- resolve(this.__result)) } },
816
- //catch: function(func){
817
- //},
818
- //finally: function(func){
819
- //},
820
-
821
- //__error: undefined,
822
- //__result: undefined,
818
+ resolve(this.value)) } },
819
+
823
820
  __new__: function(context, func){
824
821
  var result
825
822
  var resolve = function(res){
826
823
  result = res }
824
+ var rejected
827
825
  var error
828
826
  var reject = function(err){
827
+ rejected = true
829
828
  error = err }
830
-
829
+ // call...
831
830
  try{
832
831
  func(resolve, reject)
833
832
  }catch(err){
834
833
  reject(err) }
835
-
836
- if(error){
837
- this.__error = error
838
-
839
834
  // async...
840
- } else if(result instanceof Promise){
835
+ if(!error
836
+ && result instanceof Promise){
841
837
  return result }
842
-
843
838
  // sync...
844
- this.__result = result
845
- // XXX
846
- var obj = Reflect.construct(
847
- MaybePromise.__proto__,
848
- [],
849
- MaybePromise)
850
- return obj
851
- },
839
+ var obj = Promise.resolve(result)
840
+ obj.__proto__ = this.prototype
841
+ obj.value = result
842
+ rejected
843
+ && (obj.error = error)
844
+ return obj },
852
845
  })
853
846
 
854
847
 
@@ -860,8 +853,8 @@ object.Mixin('PromiseMixin', 'soft', {
860
853
  iter: IterablePromise,
861
854
  interactive: InteractivePromise,
862
855
  cooperative: CooperativePromise,
863
- // XXX
864
- //maybe: MaybePromise,
856
+ // XXX EXPEREMENTAL...
857
+ maybe: MaybePromise,
865
858
 
866
859
  // XXX need error support...
867
860
  awaitOrRun: function(data, func){
package/README.md CHANGED
@@ -94,6 +94,9 @@ Library of JavaScript type extensions, types and utilities.
94
94
  - [Promise proxies](#promise-proxies)
95
95
  - [`<promise>.as(..)`](#promiseas)
96
96
  - [`<promise-proxy>.<method>(..)`](#promise-proxymethod)
97
+ - [Sync/Async promise](#syncasync-promise)
98
+ - [`Promise.maybe(..)` / `promise.MaybePromice(..)`](#promisemaybe--promisemaybepromice)
99
+ - [`<maybe-promise>.value` / `<maybe-promise>.error`](#maybe-promisevalue--maybe-promiseerror)
97
100
  - [Promise utilities](#promise-utilities)
98
101
  - [`Promise.awaitOrRun(..)`](#promiseawaitorrun)
99
102
  - [Generator extensions and utilities](#generator-extensions-and-utilities)
@@ -2001,6 +2004,18 @@ the main `<promise>` is resolved.
2001
2004
 
2002
2005
 
2003
2006
 
2007
+ ### Sync/async promise
2008
+
2009
+
2010
+ #### `Promise.maybe(..)` / `promise.MaybePromice(..)`
2011
+
2012
+ XXX
2013
+
2014
+ #### `<maybe-promise>.value` / `<maybe-promise>.error`
2015
+
2016
+ XXX
2017
+
2018
+
2004
2019
  ### Promise utilities
2005
2020
 
2006
2021
  #### `Promise.awaitOrRun(..)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.22.2",
3
+ "version": "6.23.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {