Socket
Socket
Sign inDemoInstall

@typescript-tea/core

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

4

CHANGELOG.md

@@ -8,4 +8,6 @@ # Change Log

## [Unreleased](https://github.com/typescript-tea/core/compare/v0.3.0...master)
## [Unreleased](https://github.com/typescript-tea/core/compare/v0.4.0...master)
## [0.4.0](https://github.com/typescript-tea/core/compare/v0.3.0...0.4.0) - 2020-04-24
- Add `setup()` to `EffectManger`. This makes it possible for setup code to exist outside of core. For example code for setting up listening to popstate for navigation.

@@ -12,0 +14,0 @@ - Add generic `Init` type to `init()` function and `Program.run()` instead of passing current url. This makes it possible to pass any type of data from the outside into the init() function of the program (a litle similar to Elm's flags). Since you can pass anything, tt is still possible to pass current url.

@@ -1,3 +0,13 @@

import { LeafEffect, batchEffects, mapEffect } from "./effect";
/**
* **Note:** TEA has **managed effects**, meaning that things like HTTP
* requests or writing to disk are all treated as *data* in TEA. When this
* data is given to the TEA runtime system, it can do some “query optimization”
* before actually performing the effect. Perhaps unexpectedly, this managed
* effects idea is the heart of why TEA is so nice for testing, reuse,
* reproducibility, etc.
*
* TEA has two kinds of managed effects: commands and subscriptions.
* @packageDocumentation
*/
/**
* A command is a way of telling an EffectManager, “Hey, I want you to do this thing!”

@@ -9,4 +19,12 @@ * So if you want to send an HTTP request, you would need to command an EffectManager to do it.

* messages that will come back into your application.
* @category Commands
*/
export declare type Cmd<Action> = LeafEffect<Action>;
export declare type Cmd<Action, Home = string> = {
readonly home: Home;
readonly type: string;
/**
* This field is only needed in order to preserve the generic type paramter Action
*/
readonly __$$dummy_tag?: Action;
};
/**

@@ -17,4 +35,5 @@ * When you need the runtime system to perform a couple commands, you

* no ordering guarantees about the results.
* @category Commands
*/
export declare const batch: typeof batchEffects;
export declare function batch<A>(cmds: ReadonlyArray<Cmd<A> | undefined>): Cmd<A>;
/**

@@ -24,4 +43,5 @@ * If you are using a fractal approach where a Cmd can come from

* to produce an action that can be routed back to the child.
* @category Fancy Stuff
*/
export declare const map: typeof mapEffect;
export declare function map<A1, A2>(actionMapper: (a1: A1) => A2, cmd: Cmd<A1> | undefined): Cmd<A2> | undefined;
//# sourceMappingURL=cmd.d.ts.map

@@ -1,2 +0,2 @@

function r(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var e=t[r];if(!e)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return e}}function t(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function e(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function n(r,t,e,o,a){if(void 0===a&&(a=void 0),"__internal"===o.home){var i=o;switch(i.type){case"Batched":return void i.list.flatMap(function(o){return n(r,t,e,o,a)});case"Mapped":return void n(r,t,e,i.original,a?function(r){return a(i.actionMapper(r))}:i.actionMapper);default:throw new Error("Invalid result type "+i)}}else{var u=r(o.home);t[o.home]||(t[o.home]={cmds:[],subs:[]}),(e?t[o.home].cmds:t[o.home].subs).push(a?(e?u.mapCmd:u.mapSub)(a,o):o)}}var o={__proto__:null,run:function(t,e,o,a){void 0===a&&(a=[]);var i,u=r(a),c=t.update,f=t.view,s=t.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,i))}var b=function(r){return function(t){w(function(r){return function(t){if(v){var e=u(r),n=b(r);p[r]=e.onSelfAction(y,n,t,p[r])}}}(r),t)}},y=function(r){w(_,r)};function w(r,t){v&&(d.push({dispatch:r,action:t}),m())}function g(r){i=r[0];var t=r[1],e=s&&s(i),a={};t&&n(u,a,!0,t),e&&n(u,a,!1,e);for(var c=0,l=Object.keys(a);c<l.length;c++){var v=l[c],h=a[v],d=h.cmds,m=h.subs,_=u(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:i,dispatch:y}))}return function(){var r=a,t=Array.isArray(r),e=0;for(r=t?r:r[Symbol.iterator]();;){var n;if(t){if(e>=r.length)break;n=r[e++]}else{if((e=r.next()).done)break;n=e.value}l.push(n.setup(y,b(n.home)))}}(),v=!0,g(t.init(e)),m(),function(){v&&(v=!1,function(){var r=l,t=Array.isArray(r),e=0;for(r=t?r:r[Symbol.iterator]();;){var n;if(t){if(e>=r.length)break;n=r[e++]}else{if((e=r.next()).done)break;n=e.value}n()}}())}}},a=new Map;function i(r){return{type:"Ok",value:r}}function u(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,t){var e=a.get(t),n=e&&e.get(r);if(n)return n;var o=function(e){return t(r(e))};return e||(e=new Map,a.set(t,e)),e.set(r,o),o}},s={__proto__:null,batch:t,map:e},p={__proto__:null,Ok:i,Err:u,mapError:function(r,t){switch(t.type){case"Ok":return i(t.value);case"Err":return u(r(t.error));default:throw new Error("Invalid result type "+t)}}};exports.Cmd={__proto__:null,batch:t,map:e},exports.Dispatch=f,exports.Program=c,exports.Result=p,exports.Sub=s,exports.createGetEffectManager=r;
function r(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var n=t[r];if(!n)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return n}}function t(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function n(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function e(r,t,n,o,i){if(void 0===i&&(i=void 0),"__internal"===o.home){var a=o;switch(a.type){case"Batched":return void a.list.flatMap(function(o){return e(r,t,n,o,i)});case"Mapped":return void e(r,t,n,a.original,i?function(r){return i(a.actionMapper(r))}:a.actionMapper);default:throw new Error("Invalid result type "+a)}}else{var u=r(o.home);t[o.home]||(t[o.home]={cmds:[],subs:[]}),(n?t[o.home].cmds:t[o.home].subs).push(i?(n?u.mapCmd:u.mapSub)(i,o):o)}}var o={__proto__:null,run:function(t,n,o,i){void 0===i&&(i=[]);var a,u=r(i),c=t.update,f=t.view,s=t.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,a))}var b=function(r){return function(t){w(function(r){return function(t){if(v){var n=u(r),e=b(r);p[r]=n.onSelfAction(y,e,t,p[r])}}}(r),t)}},y=function(r){w(_,r)};function w(r,t){v&&(d.push({dispatch:r,action:t}),m())}function g(r){a=r[0];var t=r[1],n=s&&s(a),i={};t&&e(u,i,!0,t),n&&e(u,i,!1,n);for(var c=0,l=Object.keys(i);c<l.length;c++){var v=l[c],h=i[v],d=h.cmds,m=h.subs,_=u(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:a,dispatch:y}))}return function(){var r=i,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}l.push(e.setup(y,b(e.home)))}}(),v=!0,g(t.init(n)),m(),function(){v&&(v=!1,function(){var r=l,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}e()}}())}}},i=new Map;function a(r){return{type:"Ok",value:r}}function u(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,t){var n=i.get(t),e=n&&n.get(r);if(e)return e;var o=function(n){return t(r(n))};return n||(n=new Map,i.set(t,n)),n.set(r,o),o}},s={__proto__:null,batch:function(r){return t(r)},map:function(r,t){return n(r,t)}},p={__proto__:null,Ok:a,Err:u,mapError:function(r,t){switch(t.type){case"Ok":return a(t.value);case"Err":return u(r(t.error));default:throw new Error("Invalid result type "+t)}}};exports.Cmd={__proto__:null,batch:function(r){return t(r)},map:function(r,t){return n(r,t)}},exports.Dispatch=f,exports.Program=c,exports.Result=p,exports.Sub=s,exports.createGetEffectManager=r;
//# sourceMappingURL=core.js.map

@@ -1,2 +0,2 @@

function r(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var n=t[r];if(!n)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return n}}function t(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function n(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function e(r,t,n,o,i){if(void 0===i&&(i=void 0),"__internal"===o.home){var a=o;switch(a.type){case"Batched":return void a.list.flatMap(function(o){return e(r,t,n,o,i)});case"Mapped":return void e(r,t,n,a.original,i?function(r){return i(a.actionMapper(r))}:a.actionMapper);default:throw new Error("Invalid result type "+a)}}else{var u=r(o.home);t[o.home]||(t[o.home]={cmds:[],subs:[]}),(n?t[o.home].cmds:t[o.home].subs).push(i?(n?u.mapCmd:u.mapSub)(i,o):o)}}var o={__proto__:null,run:function(t,n,o,i){void 0===i&&(i=[]);var a,u=r(i),c=t.update,f=t.view,s=t.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,a))}var b=function(r){return function(t){w(function(r){return function(t){if(v){var n=u(r),e=b(r);p[r]=n.onSelfAction(y,e,t,p[r])}}}(r),t)}},y=function(r){w(_,r)};function w(r,t){v&&(d.push({dispatch:r,action:t}),m())}function g(r){a=r[0];var t=r[1],n=s&&s(a),i={};t&&e(u,i,!0,t),n&&e(u,i,!1,n);for(var c=0,l=Object.keys(i);c<l.length;c++){var v=l[c],h=i[v],d=h.cmds,m=h.subs,_=u(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:a,dispatch:y}))}return function(){var r=i,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}l.push(e.setup(y,b(e.home)))}}(),v=!0,g(t.init(n)),m(),function(){v&&(v=!1,function(){var r=l,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}e()}}())}}},i=new Map;function a(r){return{type:"Ok",value:r}}function u(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,t){var n=i.get(t),e=n&&n.get(r);if(e)return e;var o=function(n){return t(r(n))};return n||(n=new Map,i.set(t,n)),n.set(r,o),o}},s={__proto__:null,batch:t,map:n},p={__proto__:null,batch:t,map:n},l={__proto__:null,Ok:a,Err:u,mapError:function(r,t){switch(t.type){case"Ok":return a(t.value);case"Err":return u(r(t.error));default:throw new Error("Invalid result type "+t)}}};export{s as Cmd,f as Dispatch,c as Program,l as Result,p as Sub,r as createGetEffectManager};
function r(r){var n=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var t=n[r];if(!t)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return t}}function n(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function t(r,n){return void 0===n?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:n}}function e(r,n,t,o,i){if(void 0===i&&(i=void 0),"__internal"===o.home){var u=o;switch(u.type){case"Batched":return void u.list.flatMap(function(o){return e(r,n,t,o,i)});case"Mapped":return void e(r,n,t,u.original,i?function(r){return i(u.actionMapper(r))}:u.actionMapper);default:throw new Error("Invalid result type "+u)}}else{var a=r(o.home);n[o.home]||(n[o.home]={cmds:[],subs:[]}),(t?n[o.home].cmds:n[o.home].subs).push(i?(t?a.mapCmd:a.mapSub)(i,o):o)}}var o={__proto__:null,run:function(n,t,o,i){void 0===i&&(i=[]);var u,a=r(i),c=n.update,f=n.view,s=n.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,u))}var b=function(r){return function(n){w(function(r){return function(n){if(v){var t=a(r),e=b(r);p[r]=t.onSelfAction(y,e,n,p[r])}}}(r),n)}},y=function(r){w(_,r)};function w(r,n){v&&(d.push({dispatch:r,action:n}),m())}function g(r){u=r[0];var n=r[1],t=s&&s(u),i={};n&&e(a,i,!0,n),t&&e(a,i,!1,t);for(var c=0,l=Object.keys(i);c<l.length;c++){var v=l[c],h=i[v],d=h.cmds,m=h.subs,_=a(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:u,dispatch:y}))}return function(){var r=i,n=Array.isArray(r),t=0;for(r=n?r:r[Symbol.iterator]();;){var e;if(n){if(t>=r.length)break;e=r[t++]}else{if((t=r.next()).done)break;e=t.value}l.push(e.setup(y,b(e.home)))}}(),v=!0,g(n.init(t)),m(),function(){v&&(v=!1,function(){var r=l,n=Array.isArray(r),t=0;for(r=n?r:r[Symbol.iterator]();;){var e;if(n){if(t>=r.length)break;e=r[t++]}else{if((t=r.next()).done)break;e=t.value}e()}}())}}},i=new Map;function u(r){return{type:"Ok",value:r}}function a(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,n){var t=i.get(n),e=t&&t.get(r);if(e)return e;var o=function(t){return n(r(t))};return t||(t=new Map,i.set(n,t)),t.set(r,o),o}},s={__proto__:null,batch:function(r){return n(r)},map:function(r,n){return t(r,n)}},p={__proto__:null,batch:function(r){return n(r)},map:function(r,n){return t(r,n)}},l={__proto__:null,Ok:u,Err:a,mapError:function(r,n){switch(n.type){case"Ok":return u(n.value);case"Err":return a(r(n.error));default:throw new Error("Invalid result type "+n)}}};export{s as Cmd,f as Dispatch,c as Program,l as Result,p as Sub,r as createGetEffectManager};
//# sourceMappingURL=core.m.js.map

@@ -1,2 +0,2 @@

function r(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var n=t[r];if(!n)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return n}}function t(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function n(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function e(r,t,n,o,i){if(void 0===i&&(i=void 0),"__internal"===o.home){var a=o;switch(a.type){case"Batched":return void a.list.flatMap(function(o){return e(r,t,n,o,i)});case"Mapped":return void e(r,t,n,a.original,i?function(r){return i(a.actionMapper(r))}:a.actionMapper);default:throw new Error("Invalid result type "+a)}}else{var u=r(o.home);t[o.home]||(t[o.home]={cmds:[],subs:[]}),(n?t[o.home].cmds:t[o.home].subs).push(i?(n?u.mapCmd:u.mapSub)(i,o):o)}}var o={__proto__:null,run:function(t,n,o,i){void 0===i&&(i=[]);var a,u=r(i),c=t.update,f=t.view,s=t.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,a))}var b=function(r){return function(t){w(function(r){return function(t){if(v){var n=u(r),e=b(r);p[r]=n.onSelfAction(y,e,t,p[r])}}}(r),t)}},y=function(r){w(_,r)};function w(r,t){v&&(d.push({dispatch:r,action:t}),m())}function g(r){a=r[0];var t=r[1],n=s&&s(a),i={};t&&e(u,i,!0,t),n&&e(u,i,!1,n);for(var c=0,l=Object.keys(i);c<l.length;c++){var v=l[c],h=i[v],d=h.cmds,m=h.subs,_=u(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:a,dispatch:y}))}return function(){var r=i,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}l.push(e.setup(y,b(e.home)))}}(),v=!0,g(t.init(n)),m(),function(){v&&(v=!1,function(){var r=l,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}e()}}())}}},i=new Map;function a(r){return{type:"Ok",value:r}}function u(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,t){var n=i.get(t),e=n&&n.get(r);if(e)return e;var o=function(n){return t(r(n))};return n||(n=new Map,i.set(t,n)),n.set(r,o),o}},s={__proto__:null,batch:t,map:n},p={__proto__:null,batch:t,map:n},l={__proto__:null,Ok:a,Err:u,mapError:function(r,t){switch(t.type){case"Ok":return a(t.value);case"Err":return u(r(t.error));default:throw new Error("Invalid result type "+t)}}};export{s as Cmd,f as Dispatch,c as Program,l as Result,p as Sub,r as createGetEffectManager};
function r(r){var n=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var t=n[r];if(!t)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return t}}function n(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function t(r,n){return void 0===n?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:n}}function e(r,n,t,o,i){if(void 0===i&&(i=void 0),"__internal"===o.home){var u=o;switch(u.type){case"Batched":return void u.list.flatMap(function(o){return e(r,n,t,o,i)});case"Mapped":return void e(r,n,t,u.original,i?function(r){return i(u.actionMapper(r))}:u.actionMapper);default:throw new Error("Invalid result type "+u)}}else{var a=r(o.home);n[o.home]||(n[o.home]={cmds:[],subs:[]}),(t?n[o.home].cmds:n[o.home].subs).push(i?(t?a.mapCmd:a.mapSub)(i,o):o)}}var o={__proto__:null,run:function(n,t,o,i){void 0===i&&(i=[]);var u,a=r(i),c=n.update,f=n.view,s=n.subscriptions,p={},l=[],v=!1,h=!1,d=[];function m(){if(v&&!h){for(h=!0;d.length>0;){var r=d.shift();r.dispatch(r.action)}h=!1}}function _(r){v&&g(c(r,u))}var b=function(r){return function(n){w(function(r){return function(n){if(v){var t=a(r),e=b(r);p[r]=t.onSelfAction(y,e,n,p[r])}}}(r),n)}},y=function(r){w(_,r)};function w(r,n){v&&(d.push({dispatch:r,action:n}),m())}function g(r){u=r[0];var n=r[1],t=s&&s(u),i={};n&&e(a,i,!0,n),t&&e(a,i,!1,t);for(var c=0,l=Object.keys(i);c<l.length;c++){var v=l[c],h=i[v],d=h.cmds,m=h.subs,_=a(v);p[v]=_.onEffects(y,b(v),d,m,p[v])}o(f({state:u,dispatch:y}))}return function(){var r=i,n=Array.isArray(r),t=0;for(r=n?r:r[Symbol.iterator]();;){var e;if(n){if(t>=r.length)break;e=r[t++]}else{if((t=r.next()).done)break;e=t.value}l.push(e.setup(y,b(e.home)))}}(),v=!0,g(n.init(t)),m(),function(){v&&(v=!1,function(){var r=l,n=Array.isArray(r),t=0;for(r=n?r:r[Symbol.iterator]();;){var e;if(n){if(t>=r.length)break;e=r[t++]}else{if((t=r.next()).done)break;e=t.value}e()}}())}}},i=new Map;function u(r){return{type:"Ok",value:r}}function a(r){return{type:"Err",error:r}}var c=o,f={__proto__:null,map:function(r,n){var t=i.get(n),e=t&&t.get(r);if(e)return e;var o=function(t){return n(r(t))};return t||(t=new Map,i.set(n,t)),t.set(r,o),o}},s={__proto__:null,batch:function(r){return n(r)},map:function(r,n){return t(r,n)}},p={__proto__:null,batch:function(r){return n(r)},map:function(r,n){return t(r,n)}},l={__proto__:null,Ok:u,Err:a,mapError:function(r,n){switch(n.type){case"Ok":return u(n.value);case"Err":return a(r(n.error));default:throw new Error("Invalid result type "+n)}}};export{s as Cmd,f as Dispatch,c as Program,l as Result,p as Sub,r as createGetEffectManager};
//# sourceMappingURL=core.modern.js.map

@@ -1,2 +0,2 @@

!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).core={})}(this,function(r){function t(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var e=t[r];if(!e)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return e}}function e(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function n(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function o(r,t,e,n,i){if(void 0===i&&(i=void 0),"__internal"===n.home){var a=n;switch(a.type){case"Batched":return void a.list.flatMap(function(n){return o(r,t,e,n,i)});case"Mapped":return void o(r,t,e,a.original,i?function(r){return i(a.actionMapper(r))}:a.actionMapper);default:throw new Error("Invalid result type "+a)}}else{var u=r(n.home);t[n.home]||(t[n.home]={cmds:[],subs:[]}),(e?t[n.home].cmds:t[n.home].subs).push(i?(e?u.mapCmd:u.mapSub)(i,n):n)}}var i={__proto__:null,run:function(r,e,n,i){void 0===i&&(i=[]);var a,u=t(i),f=r.update,c=r.view,s=r.subscriptions,p={},l=[],d=!1,v=!1,h=[];function m(){if(d&&!v){for(v=!0;h.length>0;){var r=h.shift();r.dispatch(r.action)}v=!1}}function _(r){d&&g(f(r,a))}var y=function(r){return function(t){w(function(r){return function(t){if(d){var e=u(r),n=y(r);p[r]=e.onSelfAction(b,n,t,p[r])}}}(r),t)}},b=function(r){w(_,r)};function w(r,t){d&&(h.push({dispatch:r,action:t}),m())}function g(r){a=r[0];var t=r[1],e=s&&s(a),i={};t&&o(u,i,!0,t),e&&o(u,i,!1,e);for(var f=0,l=Object.keys(i);f<l.length;f++){var d=l[f],v=i[d],h=v.cmds,m=v.subs,_=u(d);p[d]=_.onEffects(b,y(d),h,m,p[d])}n(c({state:a,dispatch:b}))}return function(){var r=i,t=Array.isArray(r),e=0;for(r=t?r:r[Symbol.iterator]();;){var n;if(t){if(e>=r.length)break;n=r[e++]}else{if((e=r.next()).done)break;n=e.value}l.push(n.setup(b,y(n.home)))}}(),d=!0,g(r.init(e)),m(),function(){d&&(d=!1,function(){var r=l,t=Array.isArray(r),e=0;for(r=t?r:r[Symbol.iterator]();;){var n;if(t){if(e>=r.length)break;n=r[e++]}else{if((e=r.next()).done)break;n=e.value}n()}}())}}},a=new Map;function u(r){return{type:"Ok",value:r}}function f(r){return{type:"Err",error:r}}var c=i,s={__proto__:null,map:function(r,t){var e=a.get(t),n=e&&e.get(r);if(n)return n;var o=function(e){return t(r(e))};return e||(e=new Map,a.set(t,e)),e.set(r,o),o}},p={__proto__:null,batch:e,map:n},l={__proto__:null,Ok:u,Err:f,mapError:function(r,t){switch(t.type){case"Ok":return u(t.value);case"Err":return f(r(t.error));default:throw new Error("Invalid result type "+t)}}};r.Cmd={__proto__:null,batch:e,map:n},r.Dispatch=s,r.Program=c,r.Result=l,r.Sub=p,r.createGetEffectManager=t});
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).core={})}(this,function(r){function t(r){var t=function(r){return Object.fromEntries(r.map(function(r){return[r.home,r]}))}(r);return function(r){var n=t[r];if(!n)throw new Error("Could not find effect manager '"+r+"'. Make sure it was passed to the runtime.");return n}}function n(r){return{home:"__internal",type:"Batched",list:r.filter(function(r){return void 0!==r})}}function e(r,t){return void 0===t?void 0:{home:"__internal",type:"Mapped",actionMapper:r,original:t}}function o(r,t,n,e,i){if(void 0===i&&(i=void 0),"__internal"===e.home){var u=e;switch(u.type){case"Batched":return void u.list.flatMap(function(e){return o(r,t,n,e,i)});case"Mapped":return void o(r,t,n,u.original,i?function(r){return i(u.actionMapper(r))}:u.actionMapper);default:throw new Error("Invalid result type "+u)}}else{var a=r(e.home);t[e.home]||(t[e.home]={cmds:[],subs:[]}),(n?t[e.home].cmds:t[e.home].subs).push(i?(n?a.mapCmd:a.mapSub)(i,e):e)}}var i={__proto__:null,run:function(r,n,e,i){void 0===i&&(i=[]);var u,a=t(i),f=r.update,c=r.view,s=r.subscriptions,p={},l=[],d=!1,v=!1,h=[];function m(){if(d&&!v){for(v=!0;h.length>0;){var r=h.shift();r.dispatch(r.action)}v=!1}}function _(r){d&&g(f(r,u))}var y=function(r){return function(t){w(function(r){return function(t){if(d){var n=a(r),e=y(r);p[r]=n.onSelfAction(b,e,t,p[r])}}}(r),t)}},b=function(r){w(_,r)};function w(r,t){d&&(h.push({dispatch:r,action:t}),m())}function g(r){u=r[0];var t=r[1],n=s&&s(u),i={};t&&o(a,i,!0,t),n&&o(a,i,!1,n);for(var f=0,l=Object.keys(i);f<l.length;f++){var d=l[f],v=i[d],h=v.cmds,m=v.subs,_=a(d);p[d]=_.onEffects(b,y(d),h,m,p[d])}e(c({state:u,dispatch:b}))}return function(){var r=i,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}l.push(e.setup(b,y(e.home)))}}(),d=!0,g(r.init(n)),m(),function(){d&&(d=!1,function(){var r=l,t=Array.isArray(r),n=0;for(r=t?r:r[Symbol.iterator]();;){var e;if(t){if(n>=r.length)break;e=r[n++]}else{if((n=r.next()).done)break;e=n.value}e()}}())}}},u=new Map;function a(r){return{type:"Ok",value:r}}function f(r){return{type:"Err",error:r}}var c=i,s={__proto__:null,map:function(r,t){var n=u.get(t),e=n&&n.get(r);if(e)return e;var o=function(n){return t(r(n))};return n||(n=new Map,u.set(t,n)),n.set(r,o),o}},p={__proto__:null,batch:function(r){return n(r)},map:function(r,t){return e(r,t)}},l={__proto__:null,Ok:a,Err:f,mapError:function(r,t){switch(t.type){case"Ok":return a(t.value);case"Err":return f(r(t.error));default:throw new Error("Invalid result type "+t)}}};r.Cmd={__proto__:null,batch:function(r){return n(r)},map:function(r,t){return e(r,t)}},r.Dispatch=s,r.Program=c,r.Result=l,r.Sub=p,r.createGetEffectManager=t});
//# sourceMappingURL=core.umd.js.map

@@ -0,1 +1,5 @@

/**
* The dispatch function.
* @category Dispatch
*/
export declare type Dispatch<A> = (action: A) => void;

@@ -8,4 +12,5 @@ /**

* would if a lambda like (a) => dispatch(mapper(a)) was used.
* @category Fancy Stuff
*/
export declare function map<ChildAction, ParentAction>(actionMapper: (childAction: ChildAction) => ParentAction, dispatch: Dispatch<ParentAction>): Dispatch<ChildAction>;
//# sourceMappingURL=dispatch.d.ts.map
import { Dispatch } from "./dispatch";
import { LeafEffect, LeafEffectMapper } from "./effect";
import { Cmd } from "./cmd";
import { Sub } from "./sub";
/**
* A type that describes an effect manager that can be used by the runtime.
* A type that describes an effect manager that can be used by the {@link "program".run} function.
*
* @category Effect Manager
*/
export declare type EffectManager<Home = string, ProgramAction = unknown, SelfAction = unknown, SelfState = unknown, MyCmd extends LeafEffect<ProgramAction, Home> = LeafEffect<ProgramAction, Home>, MySub extends LeafEffect<ProgramAction, Home> = LeafEffect<ProgramAction, Home>> = {
export declare type EffectManager<Home = string, ProgramAction = unknown, SelfAction = unknown, SelfState = unknown, MyCmd extends Cmd<ProgramAction, Home> = Cmd<ProgramAction, Home>, MySub extends Sub<ProgramAction, Home> = Sub<ProgramAction, Home>> = {
/**
* All effect managers must have a unique `Home` string that is used to identify effects that should
* be routed to each effect manager. This is simply a string with the only constraint that is must
* be unique among all other effect managers that are used.
*/
readonly home: Home;
readonly mapCmd: LeafEffectMapper;
readonly mapSub: LeafEffectMapper;
/**
* This function is used when calling {@link "cmd".map}.
*/
readonly mapCmd: <A1, A2>(actionMapper: (a1: A1) => A2, cmd: Cmd<A1>) => Cmd<A2>;
/**
* This function is used when calling {@link "sub".map}.
*/
readonly mapSub: <A1, A2>(actionMapper: (a1: A1) => A2, sub: Sub<A1>) => Sub<A2>;
/**
* This function will be called when initializing the effect manager.
*/
readonly setup: (dispatchProgram: Dispatch<ProgramAction>, dispatchSelf: Dispatch<SelfAction>) => () => void;
/**
* This function will be called with effects emitted from the Program matching this manager's home.
*/
readonly onEffects: (dispatchProgram: Dispatch<ProgramAction>, dispatchSelf: Dispatch<SelfAction>, cmds: ReadonlyArray<MyCmd>, subs: ReadonlyArray<MySub>, state: SelfState) => SelfState;
/**
* This function will be called when the manager issues an action to itself.
*/
readonly onSelfAction: (dispatchProgram: Dispatch<ProgramAction>, dispatchSelf: Dispatch<SelfAction>, action: SelfAction, state: SelfState) => SelfState;

@@ -13,0 +36,0 @@ };

@@ -0,1 +1,2 @@

/** @ignore */ /** */
/**

@@ -2,0 +3,0 @@ * Commands and Subscriptions are both effects and they can both be batched and mapped.

@@ -7,2 +7,3 @@ import { Cmd } from "./cmd";

* A program represents the root of an application.
* @category Program
*/

@@ -23,4 +24,7 @@ export declare type Program<Init, State, Action, View> = {

* You can use the returned function to terminate the program.
* @param program This is the program to run.
* @typeParam Init This is the type of the initial value passed to the program's init function.
* @category Program
*/
export declare function run<Init, State, Action, View>(program: Program<Init, State, Action, View>, init: Init, render: (view: View) => void, effectManagers?: ReadonlyArray<EffectManager<string, unknown, unknown>>): () => void;
//# sourceMappingURL=program.d.ts.map

@@ -1,2 +0,1 @@

import { LeafEffect, batchEffects, mapEffect } from "./effect";
/**

@@ -12,9 +11,18 @@ * A subscription is a way of telling an EffectManager, "Hey, let me know if anything

* messages that will come back into your application.
* @category Subscriptions
*/
export declare type Sub<Action> = LeafEffect<Action>;
export declare type Sub<Action, Home = string> = {
readonly home: Home;
readonly type: string;
/**
* This field is only needed in order to preserve the generic type paramter Action
*/
readonly __$$dummy_tag?: Action;
};
/**
* When you need to subscribe to multiple things, you can create a `batch` of
* subscriptions.
* @category Subscriptions
*/
export declare const batch: typeof batchEffects;
export declare function batch<A>(cmds: ReadonlyArray<Sub<A> | undefined>): Sub<A>;
/**

@@ -24,4 +32,5 @@ * If you are using a fractal approach where a Sub can come from

* to produce an action that can be routed back to the child.
* @category Fancy Stuff
*/
export declare const map: typeof mapEffect;
export declare function map<A1, A2>(actionMapper: (a1: A1) => A2, cmd: Sub<A1> | undefined): Sub<A2> | undefined;
//# sourceMappingURL=sub.d.ts.map
{
"name": "@typescript-tea/core",
"version": "0.4.0",
"version": "0.5.0",
"description": "The Elm Architecture for typescript",

@@ -30,19 +30,19 @@ "main": "dist/core.js",

"devDependencies": {
"@types/jest": "^24.9.1",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"@types/jest": "^26.0.15",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"confusing-browser-globals": "^1.0.9",
"eslint": "^6.8.0",
"eslint-config-divid": "^0.4.2",
"eslint-plugin-functional": "^3.0.1",
"eslint-plugin-import": "^2.20.0",
"eslint": "^7.11.0",
"eslint-config-divid": "^0.5.1",
"eslint-plugin-functional": "^3.1.0",
"eslint-plugin-import": "^2.22.1",
"husky": "^4.2.1",
"jest": "^25.1.0",
"jest": "^26.6.0",
"lint-staged": "^10.0.2",
"microbundle": "^0.12.0-next.8",
"prettier": "^1.19.1",
"prettier": "^2.1.2",
"rimraf": "^3.0.0",
"ts-jest": "^25.0.0",
"typedoc": "^0.17.0-3",
"typescript": "^3.7.5"
"ts-jest": "^26.4.1",
"typedoc": "^0.19.2",
"typescript": "^4.0.3"
},

@@ -49,0 +49,0 @@ "scripts": {

@@ -1,3 +0,15 @@

import { LeafEffect, batchEffects, mapEffect } from "./effect";
/**
* **Note:** TEA has **managed effects**, meaning that things like HTTP
* requests or writing to disk are all treated as *data* in TEA. When this
* data is given to the TEA runtime system, it can do some “query optimization”
* before actually performing the effect. Perhaps unexpectedly, this managed
* effects idea is the heart of why TEA is so nice for testing, reuse,
* reproducibility, etc.
*
* TEA has two kinds of managed effects: commands and subscriptions.
* @packageDocumentation
*/
import { batchEffects, mapEffect } from "./effect";
// -- COMMANDS

@@ -12,4 +24,12 @@

* messages that will come back into your application.
* @category Commands
*/
export type Cmd<Action> = LeafEffect<Action>;
export type Cmd<Action, Home = string> = {
readonly home: Home;
readonly type: string;
/**
* This field is only needed in order to preserve the generic type paramter Action
*/
readonly __$$dummy_tag?: Action;
};

@@ -21,4 +41,7 @@ /**

* no ordering guarantees about the results.
* @category Commands
*/
export const batch = batchEffects;
export function batch<A>(cmds: ReadonlyArray<Cmd<A> | undefined>): Cmd<A> {
return batchEffects(cmds);
}

@@ -29,3 +52,6 @@ /**

* to produce an action that can be routed back to the child.
* @category Fancy Stuff
*/
export const map = mapEffect;
export function map<A1, A2>(actionMapper: (a1: A1) => A2, cmd: Cmd<A1> | undefined): Cmd<A2> | undefined {
return mapEffect(actionMapper, cmd);
}
// export type ActionMapper<ChildAction, ParentAction> = (childAction: ChildAction) => ParentAction;
/**
* The dispatch function.
* @category Dispatch
*/
export type Dispatch<A> = (action: A) => void;

@@ -20,2 +24,3 @@

* would if a lambda like (a) => dispatch(mapper(a)) was used.
* @category Fancy Stuff
*/

@@ -22,0 +27,0 @@ export function map<ChildAction, ParentAction>(

import { Dispatch } from "./dispatch";
import { LeafEffect, LeafEffectMapper } from "./effect";
import { Cmd } from "./cmd";
import { Sub } from "./sub";
/**
* A type that describes an effect manager that can be used by the runtime.
* A type that describes an effect manager that can be used by the {@link "program".run} function.
*
* @category Effect Manager
*/

@@ -12,9 +15,26 @@ export type EffectManager<

SelfState = unknown,
MyCmd extends LeafEffect<ProgramAction, Home> = LeafEffect<ProgramAction, Home>,
MySub extends LeafEffect<ProgramAction, Home> = LeafEffect<ProgramAction, Home>
MyCmd extends Cmd<ProgramAction, Home> = Cmd<ProgramAction, Home>,
MySub extends Sub<ProgramAction, Home> = Sub<ProgramAction, Home>
> = {
/**
* All effect managers must have a unique `Home` string that is used to identify effects that should
* be routed to each effect manager. This is simply a string with the only constraint that is must
* be unique among all other effect managers that are used.
*/
readonly home: Home;
readonly mapCmd: LeafEffectMapper;
readonly mapSub: LeafEffectMapper;
/**
* This function is used when calling {@link "cmd".map}.
*/
readonly mapCmd: <A1, A2>(actionMapper: (a1: A1) => A2, cmd: Cmd<A1>) => Cmd<A2>;
/**
* This function is used when calling {@link "sub".map}.
*/
readonly mapSub: <A1, A2>(actionMapper: (a1: A1) => A2, sub: Sub<A1>) => Sub<A2>;
/**
* This function will be called when initializing the effect manager.
*/
readonly setup: (dispatchProgram: Dispatch<ProgramAction>, dispatchSelf: Dispatch<SelfAction>) => () => void;
/**
* This function will be called with effects emitted from the Program matching this manager's home.
*/
readonly onEffects: (

@@ -27,2 +47,5 @@ dispatchProgram: Dispatch<ProgramAction>,

) => SelfState;
/**
* This function will be called when the manager issues an action to itself.
*/
readonly onSelfAction: (

@@ -29,0 +52,0 @@ dispatchProgram: Dispatch<ProgramAction>,

@@ -0,1 +1,3 @@

/** @ignore */ /** */
/**

@@ -2,0 +4,0 @@ * Commands and Subscriptions are both effects and they can both be batched and mapped.

@@ -9,2 +9,3 @@ import { Cmd } from "./cmd";

* A program represents the root of an application.
* @category Program
*/

@@ -23,2 +24,5 @@ export type Program<Init, State, Action, View> = {

* You can use the returned function to terminate the program.
* @param program This is the program to run.
* @typeParam Init This is the type of the initial value passed to the program's init function.
* @category Program
*/

@@ -89,4 +93,4 @@ export function run<Init, State, Action, View>(

const gatheredEffects: GatheredEffects<Action> = {};
cmd && gatherEffects(getEffectManager, gatheredEffects, true, cmd); // eslint-disable-line no-unused-expressions
sub && gatherEffects(getEffectManager, gatheredEffects, false, sub); // eslint-disable-line no-unused-expressions
cmd && gatherEffects(getEffectManager, gatheredEffects, true, cmd); // eslint-disable-line @typescript-eslint/no-unused-expressions,no-unused-expressions
sub && gatherEffects(getEffectManager, gatheredEffects, false, sub); // eslint-disable-line @typescript-eslint/no-unused-expressions,no-unused-expressions
for (const home of Object.keys(gatheredEffects)) {

@@ -93,0 +97,0 @@ const { cmds, subs } = gatheredEffects[home];

@@ -11,3 +11,2 @@ /**

*/
export type Result<TError, TValue> =

@@ -14,0 +13,0 @@ | { readonly type: "Ok"; readonly value: TValue }

@@ -1,2 +0,13 @@

import { LeafEffect, batchEffects, mapEffect } from "./effect";
/**
* **Note:** TEA has **managed effects**, meaning that things like HTTP
* requests or writing to disk are all treated as *data* in TEA. When this
* data is given to the TEA runtime system, it can do some “query optimization”
* before actually performing the effect. Perhaps unexpectedly, this managed
* effects idea is the heart of why TEA is so nice for testing, reuse,
* reproducibility, etc.
*
* TEA has two kinds of managed effects: commands and subscriptions.
* @packageDocumentation
*/
import { batchEffects, mapEffect } from "./effect";

@@ -15,4 +26,12 @@ // -- SUBSCRIPTIONS

* messages that will come back into your application.
* @category Subscriptions
*/
export type Sub<Action> = LeafEffect<Action>;
export type Sub<Action, Home = string> = {
readonly home: Home;
readonly type: string;
/**
* This field is only needed in order to preserve the generic type paramter Action
*/
readonly __$$dummy_tag?: Action;
};

@@ -22,4 +41,7 @@ /**

* subscriptions.
* @category Subscriptions
*/
export const batch = batchEffects;
export function batch<A>(cmds: ReadonlyArray<Sub<A> | undefined>): Sub<A> {
return batchEffects(cmds);
}

@@ -30,3 +52,6 @@ /**

* to produce an action that can be routed back to the child.
* @category Fancy Stuff
*/
export const map = mapEffect;
export function map<A1, A2>(actionMapper: (a1: A1) => A2, cmd: Sub<A1> | undefined): Sub<A2> | undefined {
return mapEffect(actionMapper, cmd);
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc