diff --git a/Promise.js b/Promise.js index 09cf3d2..072ec22 100644 --- a/Promise.js +++ b/Promise.js @@ -417,6 +417,7 @@ object.Constructor('CooperativePromise', Promise, { //--------------------------------------------------------------------- +// XXX EXPEREMENTAL... var ProxyPromise = module.ProxyPromise = object.Constructor('ProxyPromise', Promise, { @@ -478,7 +479,6 @@ object.Mixin('PromiseMixin', 'soft', { }) PromiseMixin(Promise) - // XXX EXPEREMENTAL... PromiseProtoMixin(Promise.prototype) diff --git a/README.md b/README.md index 9d57e13..5160925 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,9 @@ Library of JavaScript type extensions, types and utilities. - [`.flat(..)`](#promise-iterflat) - [`.then(..)` / `.catch(..)` / `.finally(..)`](#promise-iterthen--promise-itercatch--promise-iterfinally) - [Advanced handler](#advanced-handler) + - [Promise proxies](#promise-proxies) + - [`.as(..)`](#promiseas) + - [`.(..)`](#promise-proxymethod) - [Generator extensions and utilities](#generator-extensions-and-utilities) - [The basics](#the-basics) - [`generator.Generator`](#generatorgenerator) @@ -1621,6 +1624,56 @@ var p = Promise.iter( ``` +### Promise proxies + +_Promise proxies_ generate a set of prototype methods returning promises that when the parent promise is resolved will resolve to a specific method call. + +Example: +```javascript +var o = { + method: function(...args){ + console.log('method:', ...args) + }, +} + +var p = Peomise.cooperative().as(o) + +p.method(1, 2, 3) // returns a promise... + +// ... + +// resolving a promise will trigger all the proxy emthod execution, so +// here 'method: 1, 2, 3' will get printed... +p.set(o) + +``` + +#### `.as(..)` + +Create a promise proxy + +```bnf +.as() +.as() + -> +``` + +A proxy promise will be populated with proxy methods to all the methods of the `` or `.prototype`. + +#### `.(..)` + +When `` resolves, call the `.(..)` on the resolved value. + +```bnf +.(..) + -> +``` + +`` will resolve the the return value of the `` when +the main `` is resolved. + + + ## Generator extensions and utilities ```javascript