'use strict'; import Zone from 'zone.js'; export const zonify = function (callback) { return (typeof callback === 'function') ? Zone.current.wrap(callback) : callback; }; export const zonifyOne = function (method) { return function (one) { return method.call(this, zonify(one)); }; }; export const zonifyTwo = function (method) { return function (first, second) { return method.call(this, zonify(first), zonify(second)); }; }; export const zonifyFirst = function (method) { return function (first, second) { return method.call(this, zonify(first), second); }; }; export const zonifySecond = function (method) { return function (first, second) { return method.call(this, first, zonify(second)); }; }; export const zonifyMiddle = function (method) { return function (first, second, third) { return method.call(this, first, zonify(second), third); }; }; export const zonifyLast = function (method) { return function (...rest) { const length = rest.length; if (length > 0) { const i = rest.length - 1; rest[i] = zonify(rest[i]); } return method.apply(this, rest); }; }; export const zonifyCall = function (method) { return function (methodName, ...rest) { return this.then(function (result) { return result[methodName].apply(result, rest); }); }; }; export const zonifyCatch = function (method) { return function (...rest) { for (let i = 0, length = rest.length, argument; i < length; i++) { argument = rest[i]; if (!(argument instanceof Error)) { rest[i] = zonify(argument); } } return method.apply(this, rest); }; }; export const zonifyCoroutine = function (method) { const coroutine = zonifyFirst(method); coroutine.addYieldHandler = zonifyOne(method.addYieldHandler); return coroutine; };