hyperapplicable
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -1,5 +0,11 @@ | ||
import { ClassProp, MaybeVNode, VNode, Action, CustomPayloads, Dispatch, Effect, Unsubscribe, Dispatchable } from 'hyperapp'; | ||
import { ClassProp, MaybeVNode, VNode, Action, Dispatchable, Effect, CustomPayloads, Dispatch, Unsubscribe } from 'hyperapp'; | ||
declare const box: <S>(classProp: ClassProp, contents: MaybeVNode<S> | MaybeVNode<S>[]) => VNode<S>; | ||
declare const isAction: <S, P = any>(x: unknown) => x is Action<S, P>; | ||
declare const next: <S>(x: Dispatchable<S, any>) => Effect<S, any>; | ||
declare const readout: <S>(prop: string) => (obj: Record<string, unknown>) => VNode<S>; | ||
declare type ActionWithPayload<S, P = any> = [action: Action<S, P>, payload: P]; | ||
@@ -13,3 +19,3 @@ declare type Content<S> = number | string | MaybeVNode<S>; | ||
declare type Subscriber<S, P> = (dispatch: Dispatch<S>, payload: P) => void | Unsubscribe; | ||
declare type Transform<S, P = any> = (state: StateFormat<S>, payload: P) => StateFormat<S>; | ||
declare type Transform<S> = (state: StateFormat<S>) => StateFormat<S>; | ||
declare type View<S> = (state: S) => MaybeVNode<S>; | ||
@@ -20,12 +26,4 @@ declare type ViewComponent<S, P> = <X>(props: CustomPayloads<S, X> & P, content: MaybeVNode<S>[]) => MaybeVNode<S>; | ||
declare const handleWith: <S>(handlers: readonly Transform<S, Event>[]) => (state: StateFormat<S, any>, event: Event) => StateFormat<S, any>; | ||
declare const unite: <S>(stateForm: StateFormat<S, any>, ...transforms: Transform<S>[]) => StateFormat<S, any>; | ||
declare const isAction: <S, P = any>(x: unknown) => x is Action<S, P>; | ||
declare const next: <S>(x: Dispatchable<S, any>) => Effect<S, any>; | ||
declare const readout: <S>(prop: string) => (obj: Record<string, unknown>) => VNode<S>; | ||
declare const unite: <S, P = any>(stateForm: StateFormat<S, any>, transformation: Transform<S, any> | [Transform<S, any>, P]) => StateFormat<S, any>; | ||
declare const contentView: <S>(view: Content<S> | VistaView<S>) => (state: S) => MaybeVNode<S>[]; | ||
@@ -36,2 +34,2 @@ declare const isVista: <S>(x: unknown) => x is Vista<S>; | ||
export { ActionWithPayload, Content, CustomProps, Effecter, Reaction, StateFormat, StateWithEffects, Subscriber, Transform, View, ViewComponent, Vista, VistaView, box, contentView, handleWith, isAction, isVNode, isVista, next, readout, unite, vista }; | ||
export { ActionWithPayload, Content, CustomProps, Effecter, Reaction, StateFormat, StateWithEffects, Subscriber, Transform, View, ViewComponent, Vista, VistaView, box, contentView, isAction, isVNode, isVista, next, readout, unite, vista }; |
import { h, text } from "hyperapp"; | ||
const box = (classProp, contents) => h("div", { class: classProp }, contents); | ||
const unite = (stateForm, transformation) => { | ||
let transform, payload; | ||
if (Array.isArray(transformation)) { | ||
transform = transformation[0]; | ||
payload = transformation[1]; | ||
} else { | ||
transform = transformation; | ||
} | ||
if (!Array.isArray(stateForm)) { | ||
return transform(stateForm, payload); | ||
} | ||
const [state, ...effects] = stateForm; | ||
const nextStateForm = transform(state, payload); | ||
if (!Array.isArray(nextStateForm)) { | ||
return [nextStateForm, ...effects]; | ||
} | ||
const [nextState, ...nextEffects] = nextStateForm; | ||
return [nextState, ...effects, ...nextEffects]; | ||
}; | ||
const handleWith = (handlers) => (state, event) => handlers.reduce((stateForm, transform) => unite(stateForm, [transform, event]), state); | ||
const isAction = (x) => typeof x === "function" || Array.isArray(x) && x.length > 0; | ||
@@ -30,2 +10,21 @@ const runNext = (dispatch, x) => { | ||
const readout = (prop) => (obj) => h("pre", {}, text(`${prop}: ${JSON.stringify(obj[prop], readoutReplacer, 2)}`)); | ||
const unite = (stateForm, ...transforms) => { | ||
let result = stateForm; | ||
for (let i = 0; i < transforms.length; ++i) { | ||
const transform = transforms[i]; | ||
if (!Array.isArray(result)) { | ||
result = transform(result); | ||
} else { | ||
const [state, ...effects] = result; | ||
const nextStateForm = transform(state); | ||
if (!Array.isArray(nextStateForm)) { | ||
result = [nextStateForm, ...effects]; | ||
} else { | ||
const [nextState, ...nextEffects] = nextStateForm; | ||
result = [nextState, ...effects, ...nextEffects]; | ||
} | ||
} | ||
} | ||
return result; | ||
}; | ||
const contentView = (view) => (state) => { | ||
@@ -44,2 +43,2 @@ if (typeof view === "function") { | ||
], []); | ||
export { box, contentView, handleWith, isAction, isVNode, isVista, next, readout, unite, vista }; | ||
export { box, contentView, isAction, isVNode, isVista, next, readout, unite, vista }; |
@@ -1,1 +0,1 @@ | ||
(function(n,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("hyperapp")):typeof define=="function"&&define.amd?define(["exports","hyperapp"],r):(n=typeof globalThis!="undefined"?globalThis:n||self,r(n.hyperapplicable={},n.Hyperapp))})(this,function(n,r){"use strict";const l=(e,t)=>r.h("div",{class:e},t),f=(e,t)=>{let i,o;if(Array.isArray(t)?(i=t[0],o=t[1]):i=t,!Array.isArray(e))return i(e,o);const[s,...d]=e,u=i(s,o);if(!Array.isArray(u))return[u,...d];const[m,...N]=u;return[m,...d,...N]},A=e=>(t,i)=>e.reduce((o,s)=>f(o,[s,i]),t),p=e=>typeof e=="function"||Array.isArray(e)&&e.length>0,h=(e,t)=>{window.requestAnimationFrame(()=>e(t))},b=e=>[h,e],V=(e,t)=>typeof t=="function"?"function":t,g=e=>t=>r.h("pre",{},r.text(`${e}: ${JSON.stringify(t[e],V,2)}`)),c=e=>t=>{if(typeof e=="function"){const i=e(t);return Array.isArray(i)?i:[i]}return typeof e=="number"||typeof e=="string"?[r.text(e)]:[e]},S=e=>e==null||typeof e=="boolean"||typeof e=="function"||typeof e=="number"||typeof e=="string"||y(e),y=e=>typeof e=="object"&&e!=null&&"node"in e,a=e=>t=>Array.isArray(e)?e.reduce((i,o)=>[...i,...Array.isArray(o)?a(o)(t):c(o)(t)],[]):c(e)(t);n.box=l,n.contentView=c,n.handleWith=A,n.isAction=p,n.isVNode=y,n.isVista=S,n.next=b,n.readout=g,n.unite=f,n.vista=a,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("hyperapp")):typeof define=="function"&&define.amd?define(["exports","hyperapp"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n.hyperapplicable={},n.Hyperapp))})(this,function(n,i){"use strict";const d=(t,e)=>i.h("div",{class:t},e),l=t=>typeof t=="function"||Array.isArray(t)&&t.length>0,A=(t,e)=>{window.requestAnimationFrame(()=>t(e))},p=t=>[A,t],b=(t,e)=>typeof e=="function"?"function":e,m=t=>e=>i.h("pre",{},i.text(`${t}: ${JSON.stringify(e[t],b,2)}`)),h=(t,...e)=>{let o=t;for(let r=0;r<e.length;++r){const y=e[r];if(!Array.isArray(o))o=y(o);else{const[V,...a]=o,c=y(V);if(!Array.isArray(c))o=[c,...a];else{const[S,...N]=c;o=[S,...a,...N]}}}return o},s=t=>e=>{if(typeof t=="function"){const o=t(e);return Array.isArray(o)?o:[o]}return typeof t=="number"||typeof t=="string"?[i.text(t)]:[t]},g=t=>t==null||typeof t=="boolean"||typeof t=="function"||typeof t=="number"||typeof t=="string"||f(t),f=t=>typeof t=="object"&&t!=null&&"node"in t,u=t=>e=>Array.isArray(t)?t.reduce((o,r)=>[...o,...Array.isArray(r)?u(r)(e):s(r)(e)],[]):s(t)(e);n.box=d,n.contentView=s,n.isAction=l,n.isVNode=f,n.isVista=g,n.next=p,n.readout=m,n.unite=h,n.vista=u,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "hyperapplicable", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A utility library for Hyperapp.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8226
72