arch-stream
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.18 | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.19 | (c) 2015, falsandtru | MIT Licence */ | ||
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
@@ -60,3 +60,3 @@ 'use strict'; | ||
}; | ||
Message.prototype.trampoline_ = function (data) { | ||
Message.prototype.transport_ = function (data) { | ||
var collection = this.collection_ ? this.collection_ : this.collect_(); | ||
@@ -71,8 +71,2 @@ var delayed = false; | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result.then(resume, resume); | ||
@@ -84,2 +78,9 @@ if (called) | ||
delayed = true; | ||
return; | ||
function resume() { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.send(data); | ||
} | ||
} | ||
}; | ||
@@ -98,8 +99,12 @@ Message.prototype.clone_ = function (msg) { | ||
Message.prototype.send = function (data, async) { | ||
if (!async) { | ||
this.trampoline_(data); | ||
} else { | ||
tick_1.default(this.trampoline_.bind(this, data)); | ||
switch (true) { | ||
case !async: { | ||
this.transport_(data); | ||
return this; | ||
} | ||
default: { | ||
tick_1.default(this.transport_.bind(this, data)); | ||
return this; | ||
} | ||
} | ||
return this; | ||
}; | ||
@@ -109,7 +114,6 @@ Message.prototype.recv = function (callback) { | ||
this.collection_ = void 0; | ||
var msg = new Message(this); | ||
if (this.memory_ !== EMPTY) { | ||
this.send(this.memory_); | ||
} | ||
return msg; | ||
return new Message(this); | ||
}; | ||
@@ -512,2 +516,11 @@ Message.prototype.then = function (done, _) { | ||
} | ||
ArchStream.prototype.pipe = function (callback) { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
}; | ||
ArchStream.prototype.import = function (pm, MethodEntity) { | ||
return pm instanceof modular_1.default ? new compose_1.default().import(pm, MethodEntity) : new compose_1.default(pm); | ||
}; | ||
ArchStream.prototype.export = function (count) { | ||
return new compose_1.default().register([this.message_]).export(count); | ||
}; | ||
ArchStream.prototype.proxy_ = function (method, args) { | ||
@@ -521,10 +534,14 @@ var params = this.proxies_.filter(function (proxy) { | ||
switch (method) { | ||
case base: | ||
return ArchStream.prototype[method].call(this, params[0]); | ||
case 'import': | ||
throw new Error('ArchStream: `import` method cannot extend by proxy.'); | ||
case 'export': | ||
return ArchStream.prototype[method].apply(this.proxy_(base, params), args); | ||
default: | ||
return this.proxy_(base, params); | ||
case base: { | ||
return ArchStream.prototype[method].call(this, params[0]); | ||
} | ||
case 'import': { | ||
throw new Error('ArchStream: `import` method cannot extend by proxy.'); | ||
} | ||
case 'export': { | ||
return ArchStream.prototype[method].apply(this.proxy_(base, params), args); | ||
} | ||
default: { | ||
return this.proxy_(base, params); | ||
} | ||
} | ||
@@ -554,11 +571,2 @@ function toArray(target) { | ||
}; | ||
ArchStream.prototype.pipe = function (callback) { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
}; | ||
ArchStream.prototype.import = function (pm, MethodEntity) { | ||
return pm instanceof modular_1.default ? new compose_1.default().import(pm, MethodEntity) : new compose_1.default(pm); | ||
}; | ||
ArchStream.prototype.export = function (count) { | ||
return new compose_1.default().register([this.message_]).export(count); | ||
}; | ||
return ArchStream; | ||
@@ -565,0 +573,0 @@ }(); |
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.18 | (c) 2015, falsandtru | MIT Licence */ | ||
require=function t(e,r,n){function o(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var a=r[u]={exports:{}};e[u][0].call(a.exports,function(t){var r=e[u][1][t];return o(r?r:t)},a,a.exports,t,e,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(t,e,r){"use strict";var n=t("./decorator/bind");r.bind=n.bind},{"./decorator/bind":2}],2:[function(t,e,r){"use strict";function n(t,e,r){t[e]=t[e].bind(t)}r.bind=n},{}],3:[function(t,e,r){"use strict";function n(t){return t}var o=this&&this.__decorate||function(t,e,r,n){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,n);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,n){return void(n&&n(e,r))},void 0);case 4:return t.reduceRight(function(t,n){return n&&n(e,r,t)||t},n)}},i=t("../lib/thenable"),u=t("../decorator"),s=t("./tick"),c={},f=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=c,t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){var t=this,e=[];do e.push(t),t=t.child_;while(t);return this.collection_=e,e},t.prototype.trampoline_=function(t){for(var e=this.collection_?this.collection_:this.collect_(),r=!1,n=0;n<e.length;n++){var o=e[n];o.memory_=t;var u=o.listener(t);if(i.isThenable(u)){var s=!1,c=c||function(){s=!0,r&&o.child_&&o.child_.trampoline_(t)};if(u.then(c,c),!s)break}}r=!0},t.prototype.clone_=function(e){return e.parent?new t(this.clone_(e.parent),e.listener):new t(void 0,e.listener)},t.prototype.clone=function(){return this.clone_(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e){return e?s["default"](this.trampoline_.bind(this,t)):this.trampoline_(t),this},t.prototype.recv=function(e){this.listener=e,this.collection_=void 0;var r=new t(this);return this.memory_!==c&&this.send(this.memory_),r},t.prototype.then=function(t,e){return this.recv(t)},Object.defineProperty(t.prototype,"send",o([u.bind],t.prototype,"send",Object.getOwnPropertyDescriptor(t.prototype,"send"))),Object.defineProperty(t.prototype,"recv",o([u.bind],t.prototype,"recv",Object.getOwnPropertyDescriptor(t.prototype,"recv"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=f},{"../decorator":1,"../lib/thenable":6,"./tick":8}],4:[function(t,e,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],5:[function(t,e,r){"use strict";var n=t("../proxy/case"),o=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:n["default"],Hook:o["default"],Responsibility:i["default"]}},{"../proxy/case":9,"../proxy/hook":10,"../proxy/responsibility":11}],6:[function(t,e,r){"use strict";function n(t){return!!t&&"object"==typeof t&&"then"in t}r.isThenable=n},{}],7:[function(t,e,r){"use strict";var n=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return this.processing_.push(t),this.resolver_(t),!0;this.queue_.push(t);do this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?this.processing_.splice(e,1):this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],8:[function(t,e,r){"use strict";var n;!function(t){function e(t){o.push(t),n()}function r(){--i,n();for(var t=o.length;t-->0;)o.shift()()}function n(){if(0!==o.length)if(u)for(;2>i;)Promise.resolve().then(r),++i;else for(;i<s.length;)setTimeout(r,s[i%s.length]),++i}t.queue=e;var o=[],i=0,u="function"==typeof Promise,s=[0,4,10,20,25].reverse()}(n||(n={}));var o=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o?Function("return fn => process.nextTick(fn)")():n.queue},{}],9:[function(t,e,r){"use strict";function n(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var o=+n[e(r)+""];o>-1&&o<t.length&&t[o](r)}}var n=Object.create(null);return t.forEach(function(t,e){return n[t+""]=e}),function(t){return{pipe:r}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],10:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),u(e)}})}var r=t.pre,n=void 0===r?o["default"]:r,i=t.post,u=void 0===i?o["default"]:i;return function(t){return{pipe:e}}}var o=t("../lib/noop");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"../lib/noop":4}],11:[function(t,e,r){"use strict";function n(){function t(t,r){e.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];return e.map(function(e){return function(n){if(!(r(n)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity: "+r(n).constructor);e(n)}})},e["export"]=function(){return function(e){r(e)instanceof t&&Object.freeze(r(e))}}}var e;return function(r){return e={rule:t}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],12:[function(t,e,r){"use strict";var n=t("./modular"),o=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){for(var e=this.procs_,r=this.procs_.length,n=t.length;n--;)e[n+r]=t[n];return this},t.prototype["import"]=function(e,r){var n=this;return this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return n.extract_(t)instanceof r?e(t):0})),--e.count<0&&e.throwCountExceededError(),this.register(e.procs),this},t.prototype["export"]=function(t){return new n["default"](this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(--t.count,this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(--t.count,this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":13}],13:[function(t,e,r){"use strict";var n=t("../lib/throttle"),o=t("../lib/tick"),i=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,o["default"](function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){--this.count<0&&this.throwCountExceededError(),this.compose_(),this.last_.recv(t)},t.prototype.read=function(t){var e=this,r=!1;return this.read_(function(n){e.flow_&&o["default"](function(){return e.flow_.dequeue(n)}),r&&t(n)}),r=!0,this},t.prototype.write_=function(t){this.first_.send(t)},t.prototype.write=function(t){return this.flow_?this.flow_.enqueue(t):this.write_(t),this},t.prototype.flow=function(t,e,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new n["default"],this.flow_.flow(t,e,r),this.flow_.register(function(t){return o.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/throttle":7,"../lib/tick":8}],14:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=t("./modular"),u=function(){function t(t,e){var r=this;void 0===e&&(e=new n["default"]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&this.parent_.proxies_.forEach(function(t){return r.proxy(t)})}return t.prototype.proxy_=function(e,r){function n(t){return Array.isArray(t)?t:[t]}var o=this.proxies_.filter(function(t){return e in t&&"function"==typeof t[e]}).reduce(function(t,r){return n(r[e].apply(void 0,t)||t)},r),i="pipe";switch(e){case i:return t.prototype[e].call(this,o[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return t.prototype[e].apply(this.proxy_(i,o),r);default:return this.proxy_(i,o)}},t.prototype.proxy=function(t){var e=this,r="function"==typeof t?t():t;return this.proxies_.push(r),Object.keys(r).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof r[t]}).forEach(function(t){return e[t]=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return e.proxy_(t,r)}}),this},t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof i["default"]?(new o["default"])["import"](t,e):new o["default"](t)},t.prototype["export"]=function(t){return(new o["default"]).register([this.message_])["export"](t)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/message":3,"./compose":12,"./modular":13}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new u["default"]}var i=t("./stream/transform");r.ArchStream=i["default"];var u=t("./lib/message");r.Message=u["default"];var s=t("./lib/proxy");r.Proxy=s["default"];var c=t("./lib/tick");r.Tick=c["default"],Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var n,f={Msg:o,Proxy:s["default"],Tick:c["default"]};!function(t){t.Msg=f.Msg,t.Proxy=f.Proxy,t.Tick=f.Tick}(n||(n={})),r.Msg=o},{"./lib/message":3,"./lib/proxy":5,"./lib/tick":8,"./stream/transform":14}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream")); | ||
/*! arch-stream v0.0.19 | (c) 2015, falsandtru | MIT Licence */ | ||
require=function t(e,r,n){function o(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var a=r[u]={exports:{}};e[u][0].call(a.exports,function(t){var r=e[u][1][t];return o(r?r:t)},a,a.exports,t,e,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(t,e,r){"use strict";var n=t("./decorator/bind");r.bind=n.bind},{"./decorator/bind":2}],2:[function(t,e,r){"use strict";function n(t,e,r){t[e]=t[e].bind(t)}r.bind=n},{}],3:[function(t,e,r){"use strict";function n(t){return t}var o=this&&this.__decorate||function(t,e,r,n){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,n);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,n){return void(n&&n(e,r))},void 0);case 4:return t.reduceRight(function(t,n){return n&&n(e,r,t)||t},n)}},i=t("../lib/thenable"),u=t("../decorator"),s=t("./tick"),c={},f=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=c,t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){var t=this,e=[];do e.push(t),t=t.child_;while(t);return this.collection_=e,e},t.prototype.transport_=function(t){function e(){c=!0,n&&u.child_&&u.child_.send(t)}for(var r=this.collection_?this.collection_:this.collect_(),n=!1,o=0;o<r.length;o++){var u=r[o];u.memory_=t;var s=u.listener(t);if(i.isThenable(s)){var c=!1;if(s.then(e,e),!c)break}}n=!0},t.prototype.clone_=function(e){return e.parent?new t(this.clone_(e.parent),e.listener):new t(void 0,e.listener)},t.prototype.clone=function(){return this.clone_(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e){switch(!0){case!e:return this.transport_(t),this;default:return s["default"](this.transport_.bind(this,t)),this}},t.prototype.recv=function(e){return this.listener=e,this.collection_=void 0,this.memory_!==c&&this.send(this.memory_),new t(this)},t.prototype.then=function(t,e){return this.recv(t)},Object.defineProperty(t.prototype,"send",o([u.bind],t.prototype,"send",Object.getOwnPropertyDescriptor(t.prototype,"send"))),Object.defineProperty(t.prototype,"recv",o([u.bind],t.prototype,"recv",Object.getOwnPropertyDescriptor(t.prototype,"recv"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=f},{"../decorator":1,"../lib/thenable":6,"./tick":8}],4:[function(t,e,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],5:[function(t,e,r){"use strict";var n=t("../proxy/case"),o=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:n["default"],Hook:o["default"],Responsibility:i["default"]}},{"../proxy/case":9,"../proxy/hook":10,"../proxy/responsibility":11}],6:[function(t,e,r){"use strict";function n(t){return!!t&&"object"==typeof t&&"then"in t}r.isThenable=n},{}],7:[function(t,e,r){"use strict";var n=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return this.processing_.push(t),this.resolver_(t),!0;this.queue_.push(t);do this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?this.processing_.splice(e,1):this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],8:[function(t,e,r){"use strict";var n;!function(t){function e(t){o.push(t),n()}function r(){--i,n();for(var t=o.length;t-->0;)o.shift()()}function n(){if(0!==o.length)if(u)for(;2>i;)Promise.resolve().then(r),++i;else for(;i<s.length;)setTimeout(r,s[i%s.length]),++i}t.queue=e;var o=[],i=0,u="function"==typeof Promise,s=[0,4,10,20,25].reverse()}(n||(n={}));var o=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o?Function("return fn => process.nextTick(fn)")():n.queue},{}],9:[function(t,e,r){"use strict";function n(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var o=+n[e(r)+""];o>-1&&o<t.length&&t[o](r)}}var n=Object.create(null);return t.forEach(function(t,e){return n[t+""]=e}),function(t){return{pipe:r}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],10:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),u(e)}})}var r=t.pre,n=void 0===r?o["default"]:r,i=t.post,u=void 0===i?o["default"]:i;return function(t){return{pipe:e}}}var o=t("../lib/noop");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"../lib/noop":4}],11:[function(t,e,r){"use strict";function n(){function t(t,r){e.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];return e.map(function(e){return function(n){if(!(r(n)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity: "+r(n).constructor);e(n)}})},e["export"]=function(){return function(e){r(e)instanceof t&&Object.freeze(r(e))}}}var e;return function(r){return e={rule:t}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],12:[function(t,e,r){"use strict";var n=t("./modular"),o=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){for(var e=this.procs_,r=this.procs_.length,n=t.length;n--;)e[n+r]=t[n];return this},t.prototype["import"]=function(e,r){var n=this;return this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return n.extract_(t)instanceof r?e(t):0})),--e.count<0&&e.throwCountExceededError(),this.register(e.procs),this},t.prototype["export"]=function(t){return new n["default"](this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(--t.count,this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(--t.count,this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":13}],13:[function(t,e,r){"use strict";var n=t("../lib/throttle"),o=t("../lib/tick"),i=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,o["default"](function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){--this.count<0&&this.throwCountExceededError(),this.compose_(),this.last_.recv(t)},t.prototype.read=function(t){var e=this,r=!1;return this.read_(function(n){e.flow_&&o["default"](function(){return e.flow_.dequeue(n)}),r&&t(n)}),r=!0,this},t.prototype.write_=function(t){this.first_.send(t)},t.prototype.write=function(t){return this.flow_?this.flow_.enqueue(t):this.write_(t),this},t.prototype.flow=function(t,e,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new n["default"],this.flow_.flow(t,e,r),this.flow_.register(function(t){return o.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=i},{"../lib/throttle":7,"../lib/tick":8}],14:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=t("./modular"),u=function(){function t(t,e){var r=this;void 0===e&&(e=new n["default"]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&this.parent_.proxies_.forEach(function(t){return r.proxy(t)})}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof i["default"]?(new o["default"])["import"](t,e):new o["default"](t)},t.prototype["export"]=function(t){return(new o["default"]).register([this.message_])["export"](t)},t.prototype.proxy_=function(e,r){function n(t){return Array.isArray(t)?t:[t]}var o=this.proxies_.filter(function(t){return e in t&&"function"==typeof t[e]}).reduce(function(t,r){return n(r[e].apply(void 0,t)||t)},r),i="pipe";switch(e){case i:return t.prototype[e].call(this,o[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return t.prototype[e].apply(this.proxy_(i,o),r);default:return this.proxy_(i,o)}},t.prototype.proxy=function(t){var e=this,r="function"==typeof t?t():t;return this.proxies_.push(r),Object.keys(r).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof r[t]}).forEach(function(t){return e[t]=function(){for(var r=[],n=0;n<arguments.length;n++)r[n-0]=arguments[n];return e.proxy_(t,r)}}),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/message":3,"./compose":12,"./modular":13}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new u["default"]}var i=t("./stream/transform");r.ArchStream=i["default"];var u=t("./lib/message");r.Message=u["default"];var s=t("./lib/proxy");r.Proxy=s["default"];var c=t("./lib/tick");r.Tick=c["default"],Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var n,f={Msg:o,Proxy:s["default"],Tick:c["default"]};!function(t){t.Msg=f.Msg,t.Proxy=f.Proxy,t.Tick=f.Tick}(n||(n={})),r.Msg=o},{"./lib/message":3,"./lib/proxy":5,"./lib/tick":8,"./stream/transform":14}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream")); |
70
memo.md
# memo | ||
ArchStreamはJavaScriptによるドメイン駆動設計(DDD)を取り入れたデータ指向設計のためのライブラリである。 | ||
ArchStreamはJavaScriptによるドメイン駆動設計(DDD)を取り入れたデータ指向設計のためのライブラリーである。 | ||
依存関係の事前条件への変換、依存関係の直列化および依存関係数制限によりシーケンスの依存関係が証明されたアーキテクチャを構築する。 | ||
@@ -9,5 +9,5 @@ | ||
エンティティの運搬とストリームのモジュール化に特化しており、エンティティの型と参照を経路で変更できず、入出力箇所をそれぞれ1つしか持たない厳格なパイプラインを構築する。 | ||
ストリームは原則として独立したモジュールとなるモジュラストリームへ変換して管理し、これを合成することでパイプラインを構築する。 | ||
Stream APIやUnderscoreがデータ操作、RxJSがSmartUI(View)をターゲットにしているのに対して、ArchStreamはアーキテクチャ設計(Model)をターゲットにしている。 | ||
ArchStreamを使用した設計として、パイプラインで構成されたドメインレイヤを持つドメイン駆動設計で構築されたモデルを持つMVC設計といった例が考えられる。 | ||
ストリームは原則として独立したモジュールとなるモジュラーストリームへ変換して管理し、これを合成することでパイプラインを構築する。 | ||
Stream APIやUnderscoreがデータ操作、RxJSがSmartUI(View)をターゲットにしているのに対して、ArchStreamはアーキテクチャ設計(Model)をターゲットにしている。 | ||
ArchStreamを使用した設計として、パイプラインで構成されたドメインレイヤーを持つドメイン駆動設計で構築されたモデルを持つMVC設計といった例が考えられる。 | ||
@@ -19,3 +19,3 @@ ## 用語 | ||
インポート・エクスポート前のArchStreamのストリーム。 | ||
具体的な処理を定義可能な唯一のストリーム。 | ||
ストリームデータを処理する関数を定義可能な唯一のストリーム。 | ||
@@ -27,5 +27,5 @@ または、包括的な意味でのストリーム。 | ||
インポート後エクスポート前のストリーム。 | ||
モジュラストリームを合成可能なストリーム。 | ||
モジュラーストリームを合成可能なストリーム。 | ||
### モジュラストリーム | ||
### モジュラーストリーム | ||
@@ -45,3 +45,3 @@ エクスポート後のストリーム。 | ||
意味のある単位まで構築され入出力の行われるストリーム。 | ||
モジュラストリームのみで構成される。 | ||
モジュラーストリームのみで構成される。 | ||
構築時点で経路が固定され動的に変更されない。 | ||
@@ -85,3 +85,3 @@ エンティティの種類ごとに構築すべきものとなる。 | ||
パイプラインに追加された関数部分。 | ||
パイプラインに定義された関数部分。 | ||
@@ -94,3 +94,3 @@ ## 目的 | ||
ストリームのエンティティの型は不変であり経路で型を変更できない。 | ||
ストリームのメソッドはコールバックの戻り値を無視し経路でエンティティの参照(実体の同一性)を変更できない。 | ||
ストリームのメソッドはコールバックの戻り値を無視し経路でエンティティの参照(実体の同一性)を変更できない。 | ||
ストリームの入出力はそれぞれ1箇所のみに限定され複数の入出力を作ることができない。 | ||
@@ -100,3 +100,3 @@ シーケンス図で書くような直線的な順次処理が中心となるアプリケーションに適している。 | ||
入出力を各1箇所に限定し、パイプラインがエンティティの種類ごとに構築するものである都合上、独立した多数の機能やアクセスポイントの提供を目的とするモデルへの適用は難しい。 | ||
アーキテクチャ設計のためのライブラリではあるが、アーキテクチャ全体をストリームで構築する設計は適切でなく、ストリームが効果的に関与できる範囲は限定的であるため、ArchStreamの適用範囲は基本的に特にシーケンスに注目される部分(UMLならシーケンス図がある部分)のみとなる。 | ||
アーキテクチャ設計のためのライブラリーではあるが、アーキテクチャ全体をストリームで構築する設計は適切でなく、ストリームが効果的に関与できる範囲は限定的であるため、ArchStreamの適用範囲は基本的に特にシーケンスに注目される部分(UMLならシーケンス図がある部分)のみとなる。 | ||
アプリケーションの目的がサービスの提供である場合、基本的に特定のユースケースのために作られるためパイプライン化しやすい。 | ||
@@ -107,12 +107,12 @@ | ||
プログラムの具体的処理を記述する関数を依存関係の最深部に凝集し、 | ||
それ以外の中継的な関数を最深部の関数までエンティティを運搬することにのみ責務を負わせて関数の責務を分離することで真に依存関係があり呼び出される関数の数とその組み合わせサイズを最小化する。 | ||
それ以外の中継的な関数を最深部の関数までエンティティを運搬することにのみ責務を負わせて関数の責務を分離することで真に依存関係があり呼びだされる関数の数とその組み合わせサイズを最小化する。 | ||
これによりドメイン指向設計のレイヤー化アーキテクチャとCQRSによる構造分割をさらに進める。 | ||
CQRSが垂直方向の分離とすると運搬責務による分離は水平方向の分離となる。 | ||
依存関係を木構造で表すならば、ノードがモジュラストリームのみ存在する運搬責務区分、リーフが具体的処理を行う関数とそれを追加するストリームのみ存在するコマンドクエリ責務区分に区分される。 | ||
依存関係を木構造で表すならば、ノードがモジュラーストリームのみ存在する運搬責務区分、リーフが具体的処理を行う関数とそれを追加するストリームのみ存在するコマンドクエリ責務区分に区分される。 | ||
さらに正確にはリーフをコマンドクエリ責務区分の依存関係の木構造に置き換えて運搬責務区分の木構造に接続した構造が適切である。 | ||
運搬責務区分の関数はパイプラインの安定的な静的構造を構築する以外の機能を持たないためコマンドクエリ責務区分である末端のモジュールに個別に関心を持つ限り上部のコマンドクエリ責務区分の中を見る必要がない。 | ||
ストリームの実装においても末端の処理が集積されるルート以外のモジュラストリームはパイプライン構築後の稼動時において何の機能も持たず実質的に空のストリームであり、 | ||
ストリームの実装においても末端の処理が集積されるルート以外のモジュラーストリームはパイプライン構築後の稼動時において何の機能も持たず実質的に空のストリームであり、 | ||
運搬責務区分の関数は構築時にしか使用されないため稼動時には実質的に消滅し、コマンドクエリ責務区分の関数だけが残る。 | ||
依存関係の木構造はディレクトリ構造と一致させると依存関係を管理しやすい。 | ||
依存関係の木構造はディレクトリー構造と一致させると依存関係を管理しやすい。 | ||
@@ -129,3 +129,3 @@ ### 関心対象の局所化 | ||
データセットの作成に必要なすべての知識が少なくとも1つのストリーム内で完結する。 | ||
データセットの初期値とパラメータは外部で持つ。 | ||
データセットの初期値とパラメーターは外部で持つ。 | ||
@@ -142,3 +142,3 @@ ### 依存関係の事前条件への変換 | ||
パイプラインを構成するモジュールの依存関係は直列となるため各依存関係が直前の依存関係を事前条件により表明することですべての依存関係が求める順序で満たされていることが証明される。 | ||
モジュラストリームは既定で1回しか合成できないため、このときパイプラインを構成するモジュールの依存関係がパイプライン内で完結密閉され外部に流失していないことも証明される。 | ||
モジュラーストリームはデフォルトで1回しか合成できないため、このときパイプラインを構成するモジュールの依存関係がパイプライン内で完結密閉され外部に流失していないことも証明される。 | ||
複数回の合成においても合成回数を指定することで依存関係を意図せず拡散して張り巡らされないよう管理下に置く。 | ||
@@ -154,4 +154,4 @@ | ||
APIをコマンドとクエリに変換し、入出力ともに1つに固定された単一のパイプラインの順次処理で表現することで各工程で必要な処理を明確化し、依存関係と分岐処理の組み合わせサイズの増大を抑える。 | ||
内部APIは使用される組み合わせがパイプラインにより固定されるため、テストにおいてAPIの組み合わせを網羅する必要がなく、パイプラインに対して単体テストを行えば足りる。 | ||
モジュラストリームは複雑化の回避のため既定で1回しか合成できないよう制限されている。 | ||
内部APIは使用される組み合わせがパイプラインにより固定されるため、テストにおいてAPIの組み合わせを網羅する必要がなく、パイプラインに対してユニットテストを行えば足りる。 | ||
モジュラーストリームは複雑化の回避のためデフォルトで1回しか合成できないよう制限されている。 | ||
@@ -168,13 +168,13 @@ ### 疎結合化 | ||
Thenableオブジェクトによる非同期処理を任意に組み込めるため、チェイン単位のコルーチン的な使用に対応する。 | ||
Thenableオブジェクトによる非同期処理を任意に組み込め、チェイン単位のコルーチン的な使用に対応する。 | ||
## 特徴と制約 | ||
- Nodeとブラウザの両方で動作するがブラウザアプリケーションをメインターゲットとする。 | ||
- Nodeとブラウザーの両方で動作するがブラウザーアプリケーションをメインターゲットとする。 | ||
- 入出力ともに1つしか存在せず、APIはコマンドまたはクエリに変換しなければならない。 | ||
- 出力を読み込めるのは1関数のみで2つ以上の関数に出力することはできない。 | ||
- 入出力データにエンティティを使用することを前提としており、接続するすべてのストリームの型が同じでなければならない。 | ||
- 入出力データの参照(同一性)は不変であり、データを置換することはできず、出力から結果を得るには入出力データのプロパティに結果を格納するほかない。 | ||
- 入出力データの参照(同一性)は不変であり、データを置換することはできず、出力から結果を得るには入出力データのプロパティに結果を格納するほかない。 | ||
- Thenableオブジェクトは直接入出力データに使用できず、エンティティでラップする必要がある。 | ||
- モジュラストリームは既定で1回しか合成できない。 | ||
- モジュラーストリームはデフォルトで1回しか合成できない。 | ||
- 条件付きインポートはパイプライン全体のうち1ストリームでしか行えない。 | ||
@@ -198,3 +198,3 @@ - 同期処理であるため1チェインごとに遅延されるStream APIより1000倍程度高速となる。 | ||
ストリームに処理を追加する。 | ||
ストリームに処理を定義する。 | ||
@@ -209,4 +209,4 @@ ```ts | ||
モジュラストリームを生成する。 | ||
既定で1回しか合成できず、複数回合成可能するにはexport時に回数を指定する必要がある。 | ||
モジュラーストリームを生成する。 | ||
デフォルトで1回しか合成できず、複数回合成可能するにはexport時に回数を指定する必要がある。 | ||
@@ -222,3 +222,3 @@ ```ts | ||
モジュラストリームを合成する。 | ||
モジュラーストリームを合成する。 | ||
条件付きインポートではメソッドを表現する。 | ||
@@ -235,3 +235,3 @@ | ||
モジュラストリームの出力を読む。 | ||
モジュラーストリームの出力を読む。 | ||
1つのリスナーのみ登録できる。 | ||
@@ -246,3 +246,3 @@ 過去の出力は再出力しない。 | ||
モジュラストリームへ入力する。 | ||
モジュラーストリームへ入力する。 | ||
@@ -259,3 +259,2 @@ ```ts | ||
任意のプロキシによりAPIを追加および変更することができる。 | ||
pipeメソッドを基底とし、メソッドの変更は多重適用される。 | ||
ストリームの型の拡張が不完全なため複数プロキシ適用時のメソッドの型情報が誤っている場合がある。 | ||
@@ -270,3 +269,3 @@ | ||
入力があふれた場合に任意のキューを消したり、文脈解釈とあわせて処理中の任意のデータのステートを変更して以降の処理をキャンセルするといった対応が可能。 | ||
Nodeのための機能。クライアントブラウザでは基本使わなくてよい。なのでやっつけ実装。 | ||
Nodeのための機能。クライアントブラウザーでは基本使わなくてよい。なのでやっつけ実装。 | ||
@@ -312,5 +311,10 @@ ```ts | ||
ストリームのメソッドを追加および変更する。 | ||
ストリームのAPIを拡張する。 | ||
カスタムプロキシを作成することで任意の拡張が可能。 | ||
同一のAPIの拡張は適用順に多重適用される。 | ||
pipeメソッドがすべての拡張の基底となり、pipeメソッドの拡張はすべてのメソッドに適用される。 | ||
メソッド名は先頭および末尾がアンダースコアであってはならない。 | ||
importメソッドを拡張することはできない。 | ||
exportメソッドの拡張は基底のメソッドの実行後にexportメソッドを呼びだす。 | ||
以下のビルトインプロキシのファクトリメソッドを提供している。 | ||
カスタムプロキシを作成して使用することも可能。 | ||
@@ -317,0 +321,0 @@ #### Case |
{ | ||
"name": "arch-stream", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "Modular stream for domain and data oriented program architecture design.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -102,24 +102,24 @@ # ArchStream | ||
const add1 = | ||
ArchStream<{val: number}>() | ||
.pipe(e => ++e.val) | ||
.export(Infinity), | ||
add2 = | ||
ArchStream<{val: number}>() | ||
.import(add1) | ||
.import(add1) | ||
.export(Infinity), | ||
add3 = | ||
ArchStream<{val: number}>() | ||
.import(add1) | ||
.import(add2) | ||
.export(); | ||
ArchStream<{val: number}>() | ||
.pipe(e => ++e.val) | ||
.export(Infinity); | ||
const add2 = | ||
ArchStream<{val: number}>() | ||
.import(add1) | ||
.import(add1) | ||
.export(Infinity); | ||
const add3 = | ||
ArchStream<{val: number}>() | ||
.import(add1) | ||
.import(add2) | ||
.export(); | ||
ArchStream<{val: number}>() | ||
.import(add1) | ||
.import(add2) | ||
.import(add3) | ||
.export() | ||
.read(e => console.log(e.val)) | ||
.write({val: 0}) // => 6 | ||
.write({val: 9}); // => 15 | ||
.import(add1) | ||
.import(add2) | ||
.import(add3) | ||
.export() | ||
.read(e => console.log(e.val)) | ||
.write({val: 0}) // => 6 | ||
.write({val: 9}); // => 15 | ||
``` | ||
@@ -133,9 +133,9 @@ | ||
A<{val: number}>() | ||
.pipe(e => new Promise(resolve => resolve(++e.val))) | ||
.pipe(e => A.Msg().send(++e.val, true)) | ||
.pipe(e => A.Msg().send(++e.val)) | ||
.export() | ||
.read(n => console.log(n)) | ||
.write({val: 1}) // => 4 | ||
.write({val: 2}); // => 5 | ||
.pipe(e => new Promise(resolve => resolve(++e.val))) | ||
.pipe(e => A.Msg().send(++e.val, true)) | ||
.pipe(e => A.Msg().send(++e.val)) | ||
.export() | ||
.read(n => console.log(n)) | ||
.write({val: 1}) // => 4 | ||
.write({val: 2}); // => 5 | ||
``` | ||
@@ -153,8 +153,8 @@ | ||
const enum State { | ||
pending, | ||
resolved, | ||
rejected | ||
pending, | ||
resolved, | ||
rejected | ||
} | ||
interface Entity { | ||
state: State; | ||
state: State; | ||
} | ||
@@ -169,3 +169,3 @@ | ||
.export() | ||
.read(e => console.log(e.val)) | ||
.read(e => console.log(e.val)) | ||
.write({state: State.pending}); // => 20 (pending => resolved => resolved => 20 => 20); | ||
@@ -180,3 +180,3 @@ ``` | ||
Freeze the ruled object in an entity. | ||
Freeze the ruled object inside an entity. | ||
@@ -187,8 +187,8 @@ ```ts | ||
A<{val: number}>() | ||
.proxy(A.Proxy.Responsibility()) | ||
.rule(e => e) | ||
.pipe(e => ++e.val) | ||
.export() // freeze the entity | ||
.read(e => console.log(e.val)) | ||
.write({val: 0}); // => 1 | ||
.proxy(A.Proxy.Responsibility()) | ||
.rule(e => e) | ||
.pipe(e => ++e.val) | ||
.export() // freeze the entity | ||
.read(e => console.log(e.val)) | ||
.write({val: 0}); // => 1 | ||
``` | ||
@@ -195,0 +195,0 @@ |
@@ -43,3 +43,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
}; | ||
Message.prototype.trampoline_ = function (data) { | ||
Message.prototype.transport_ = function (data) { | ||
var collection = this.collection_ ? this.collection_ : this.collect_(); | ||
@@ -54,8 +54,2 @@ var delayed = false; | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result | ||
@@ -68,2 +62,9 @@ .then(resume, resume); | ||
delayed = true; | ||
return; | ||
function resume() { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.send(data); | ||
} | ||
} | ||
}; | ||
@@ -88,9 +89,13 @@ Message.prototype.clone_ = function (msg) { | ||
assert(typeof async === 'boolean' || async === void 0); | ||
if (!async) { | ||
this.trampoline_(data); | ||
switch (true) { | ||
case !async: { | ||
this.transport_(data); | ||
return this; | ||
} | ||
default: { | ||
tick_1.default(this.transport_.bind(this, data)); | ||
return this; | ||
} | ||
} | ||
else { | ||
tick_1.default(this.trampoline_.bind(this, data)); | ||
} | ||
return this; | ||
assert(false); | ||
}; | ||
@@ -102,7 +107,6 @@ Message.prototype.recv = function (callback) { | ||
this.collection_ = void 0; | ||
var msg = new Message(this); | ||
if (this.memory_ !== EMPTY) { | ||
this.send(this.memory_); | ||
} | ||
return msg; | ||
return new Message(this); | ||
}; | ||
@@ -109,0 +113,0 @@ Message.prototype.then = function (done, _) { |
@@ -44,3 +44,3 @@ import {Message as IMessage, ICallback} from 'arch-stream'; | ||
private trampoline_(data: T): void { | ||
private transport_(data: T): void { | ||
const collection = this.collection_ ? this.collection_ : this.collect_(); | ||
@@ -56,8 +56,2 @@ let delayed = false; | ||
var called = false; | ||
var resume = resume || function () { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.trampoline_(data); | ||
} | ||
}; | ||
result | ||
@@ -69,2 +63,10 @@ .then(resume, resume); | ||
delayed = true; | ||
return; | ||
function resume() { | ||
called = true; | ||
if (delayed && msg.child_) { | ||
msg.child_.send(data); | ||
} | ||
} | ||
} | ||
@@ -94,9 +96,13 @@ | ||
assert(typeof async === 'boolean' || async === void 0); | ||
if (!async) { | ||
this.trampoline_(data); | ||
switch (true) { | ||
case !async: { | ||
this.transport_(data); | ||
return this; | ||
} | ||
default: { | ||
Tick(this.transport_.bind(this, data)); | ||
return this; | ||
} | ||
} | ||
else { | ||
Tick(this.trampoline_.bind(this, data)); | ||
} | ||
return this; | ||
assert(false); | ||
} | ||
@@ -110,7 +116,6 @@ | ||
this.collection_ = void 0; | ||
const msg = new Message<T>(this); | ||
if (this.memory_ !== EMPTY) { | ||
this.send(this.memory_); | ||
} | ||
return msg; | ||
return new Message<T>(this); | ||
} | ||
@@ -117,0 +122,0 @@ |
@@ -12,3 +12,4 @@ function default_1() { | ||
} | ||
return args.map(function (callback) { | ||
return args | ||
.map(function (callback) { | ||
return function (entity) { | ||
@@ -15,0 +16,0 @@ if (extract(entity) instanceof LocalEntity) { |
@@ -15,12 +15,13 @@ import {ICallback, ITransformStream} from 'arch-stream'; | ||
proxy.pipe = (...args: ICallback<T>[]) => | ||
args.map(callback => | ||
(entity: T) => { | ||
if (extract(entity) instanceof LocalEntity) { | ||
callback(entity); | ||
args | ||
.map(callback => | ||
(entity: T) => { | ||
if (extract(entity) instanceof LocalEntity) { | ||
callback(entity); | ||
} | ||
else { | ||
throw TypeError(`ArchStream: ResponsibilityProxy: Uncovered internal entity: ${extract(entity).constructor}`); | ||
} | ||
} | ||
else { | ||
throw TypeError(`ArchStream: ResponsibilityProxy: Uncovered internal entity: ${extract(entity).constructor}`); | ||
} | ||
} | ||
); | ||
); | ||
proxy.export = () => | ||
@@ -27,0 +28,0 @@ (entity: T) => { |
@@ -17,3 +17,3 @@ import {IComposeStream} from 'arch-stream'; | ||
} | ||
public import<V>(module: ModularStream<T>, MethodEntity?: new (...args: any[]) => V): ComposeStream<T> { | ||
public import<V>(module: ModularStream<T>, MethodEntity?: new (..._) => V): ComposeStream<T> { | ||
assert(module.procs.length > 0); | ||
@@ -20,0 +20,0 @@ this.throwErrorIfNotImportable_(module, MethodEntity); |
@@ -21,2 +21,13 @@ var message_1 = require('../lib/message'); | ||
} | ||
ArchStream.prototype.pipe = function (callback) { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
}; | ||
ArchStream.prototype.import = function (pm, MethodEntity) { | ||
return pm instanceof modular_1.default | ||
? new compose_1.default().import(pm, MethodEntity) | ||
: new compose_1.default(pm); | ||
}; | ||
ArchStream.prototype.export = function (count) { | ||
return new compose_1.default().register([this.message_]).export(count); | ||
}; | ||
ArchStream.prototype.proxy_ = function (method, args) { | ||
@@ -29,11 +40,16 @@ assert(this.proxies_.length > 0); | ||
switch (method) { | ||
case base: | ||
case base: { | ||
return ArchStream.prototype[method].call(this, params[0]); | ||
case 'import': | ||
} | ||
case 'import': { | ||
throw new Error('ArchStream: `import` method cannot extend by proxy.'); | ||
case 'export': | ||
} | ||
case 'export': { | ||
return ArchStream.prototype[method].apply(this.proxy_(base, params), args); | ||
default: | ||
} | ||
default: { | ||
return this.proxy_(base, params); | ||
} | ||
} | ||
assert(false); | ||
function toArray(target) { | ||
@@ -59,13 +75,2 @@ return Array.isArray(target) ? target : [target]; | ||
}; | ||
ArchStream.prototype.pipe = function (callback) { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
}; | ||
ArchStream.prototype.import = function (pm, MethodEntity) { | ||
return pm instanceof modular_1.default | ||
? new compose_1.default().import(pm, MethodEntity) | ||
: new compose_1.default(pm); | ||
}; | ||
ArchStream.prototype.export = function (count) { | ||
return new compose_1.default().register([this.message_]).export(count); | ||
}; | ||
return ArchStream; | ||
@@ -72,0 +77,0 @@ })(); |
@@ -22,2 +22,15 @@ import {ArchStream as IArchStream, ITransformStream, ICallback} from 'arch-stream'; | ||
} | ||
public pipe(callback: ICallback<T>): ArchStream<T> { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
} | ||
public import<V>(extract: (entity: T) => V) | ||
public import<V>(module: ModularStream<T>, MethodEntity?: new (..._) => V): ComposeStream<T> | ||
public import<V>(pm: ModularStream<T>|((entity: T) => V), MethodEntity?: new (..._) => V): ComposeStream<T> { | ||
return pm instanceof ModularStream | ||
? new ComposeStream<T>().import(pm, MethodEntity) | ||
: new ComposeStream<T>(<(entity: T) => V>pm); | ||
} | ||
public export(count?: number): ModularStream<T> { | ||
return new ComposeStream<T>().register([this.message_]).export(count); | ||
} | ||
// mutable | ||
@@ -32,11 +45,16 @@ private proxies_: IProxy<T>[] = []; | ||
switch (method) { | ||
case base: | ||
case base: { | ||
return ArchStream.prototype[method].call(this, params[0]); | ||
case 'import': | ||
} | ||
case 'import': { | ||
throw new Error('ArchStream: `import` method cannot extend by proxy.'); | ||
case 'export': | ||
} | ||
case 'export': { | ||
return ArchStream.prototype[method].apply(this.proxy_<S>(base, params), args); | ||
default: | ||
} | ||
default: { | ||
return this.proxy_<S>(base, params); | ||
} | ||
} | ||
assert(false); | ||
@@ -56,15 +74,2 @@ function toArray<T>(target: T|T[]): T[] { | ||
} | ||
public pipe(callback: ICallback<T>): ArchStream<T> { | ||
return new ArchStream(this, this.message_.recv(callback)); | ||
} | ||
public import<V>(extract: (entity: T) => V) | ||
public import<V>(module: ModularStream<T>, MethodEntity?: new (...args: any[]) => V): ComposeStream<T> | ||
public import<V>(pm: ModularStream<T>|((entity: T) => V), MethodEntity?: new (...args: any[]) => V): ComposeStream<T> { | ||
return pm instanceof ModularStream | ||
? new ComposeStream<T>().import(pm, MethodEntity) | ||
: new ComposeStream<T>(<(entity: T) => V>pm); | ||
} | ||
public export(count?: number): ModularStream<T> { | ||
return new ComposeStream<T>().register([this.message_]).export(count); | ||
} | ||
} |
@@ -28,3 +28,3 @@ { | ||
"no-string-literal": true, | ||
"no-switch-case-fall-through": true, | ||
"no-switch-case-fall-through": false, | ||
"no-trailing-comma": true, | ||
@@ -31,0 +31,0 @@ "no-trailing-whitespace": false, |
@@ -28,3 +28,3 @@ { | ||
"no-string-literal": true, | ||
"no-switch-case-fall-through": true, | ||
"no-switch-case-fall-through": false, | ||
"no-trailing-comma": true, | ||
@@ -31,0 +31,0 @@ "no-trailing-whitespace": false, |
148008
3438