Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

hyperapp

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperapp - npm Package Compare versions

Comparing version 0.16.0 to 0.16.1

2

dist/hyperapp.js

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.hyperapp={})}(this,function(e){"use strict";function n(e,n){function r(e,n){return e&&t(e.tagName.toLowerCase(),{},n.call(e.childNodes,function(e){return 3===e.nodeType?e.nodeValue:r(e,n)}))}function o(){e.view&&!m&&setTimeout(i,m=!m)}function i(t){for(m=!m,(t=e.view(k,N))&&!m&&(w=g(n,w,b,b=t));t=x.pop();)t()}function u(e,n,t,r){var o=t.modules;f(e,n,t.actions,r),c(e,t.state);for(var i in o)u(e[i]={},n[i]={},o[i],r.concat(i))}function f(e,n,t,r){Object.keys(t||{}).map(function(i){"function"==typeof t[i]?n[i]=function(u){var f=t[i](e=s(r,k),n);return"function"==typeof f&&(f=f(u)),f&&f!==e&&!f.then&&o(k=l(r,p(e,f),k)),f}:f(e[i]||(e[i]={}),n[i]={},t[i],r.concat(i))})}function p(e,n){return c(c({},e),n)}function c(e,n){for(var t in n)e[t]=n[t];return e}function l(e,n,t){var r={};return 0===e.length?n:(r[e[0]]=1<e.length?l(e.slice(1),n,t[e[0]]):n,p(t,r))}function s(e,n){for(var t=0;t<e.length;t++)n=n[e[t]];return n}function a(e,n){if("string"==typeof e)var t=document.createTextNode(e);else{var t=(n=n||"svg"===e.type)?document.createElementNS("http://www.w3.org/2000/svg",e.type):document.createElement(e.type);e.props.oncreate&&x.push(function(){e.props.oncreate(t)});for(var r=0;r<e.children.length;r++)t.appendChild(a(e.children[r],n));for(var r in e.props)d(t,r,e.props[r])}return t}function d(e,n,t,r){if("key"===n);else if("style"===n)for(var n in p(r,t=t||{}))e.style[n]=t[n]||"";else{try{e[n]=null==t?"":t}catch(e){}"function"!=typeof t&&(null==t||!1===t?e.removeAttribute(n):e.setAttribute(n,t))}}function h(e,n,t){for(var r in p(n,t)){var o=t[r],i="value"===r||"checked"===r?e[r]:n[r];o!==i&&d(e,r,o,i)}t.onupdate&&x.push(function(){t.onupdate(e,n)})}function v(e,n,t){function r(){e.removeChild(n)}t&&t.onremove?t.onremove(n,r):r()}function y(e){if(e&&e.props)return e.props.key}function g(e,n,t,r,o,i){if(t===r);else if(null==t)n=e.insertBefore(a(r,o),n);else if(null!=r.type&&r.type===t.type){h(n,t.props,r.props),o=o||"svg"===r.type;for(var u=r.children.length,f=t.children.length,p={},c=[],l={},s=0;s<f;s++){var d=c[s]=n.childNodes[s],m=t.children[s],w=y(m);null!=w&&(p[w]=[d,m])}for(var s=0,b=0;b<u;){var d=c[s],m=t.children[s],k=r.children[b],w=y(m);if(l[w])s++;else{var N=y(k),x=p[N]||[];null==N?(null==w&&(g(n,d,m,k,o),b++),s++):(w===N?(g(n,x[0],x[1],k,o),s++):x[0]?(n.insertBefore(x[0],d),g(n,x[0],x[1],k,o)):g(n,d,null,k,o),b++,l[N]=k)}}for(;s<f;){var m=t.children[s],w=y(m);null==w&&v(n,c[s],m.props),s++}for(var s in p){var x=p[s],A=x[1];l[A.props.key]||v(n,x[0],A.props)}}else n&&r!==n.nodeValue&&("string"==typeof r&&"string"==typeof t?n.nodeValue=r:(n=e.insertBefore(a(r,o),i=n),v(e,i,t.props)));return n}var m,w=(n=n||document.body).children[0],b=r(w,[].map),k={},N={},x=[];return o(u(k,N,e,[])),N}function t(e,n){for(var t,r=[],o=[],i=arguments.length;i-- >2;)r.push(arguments[i]);for(;r.length;)if(Array.isArray(t=r.pop()))for(i=t.length;i--;)r.push(t[i]);else null!=t&&!0!==t&&!1!==t&&o.push("number"==typeof t?t+="":t);return"string"==typeof e?{type:e,props:n||{},children:o}:e(n||{},o)}e.h=t,e.app=n});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.hyperapp={})}(this,function(e){"use strict";function n(e,n){function t(e,n){return e&&r(e.tagName.toLowerCase(),{},n.call(e.childNodes,function(e){return 3===e.nodeType?e.nodeValue:t(e,n)}))}function o(e,n){for(var r in n)e[r]=n[r];return e}function i(e,n){return o(o({},e),n)}function u(e,n,r){var t={};return 0===e.length?n:(t[e[0]]=1<e.length?u(e.slice(1),n,r[e[0]]):n,i(r,t))}function f(e,n){for(var r=0;r<e.length;r++)n=n[e[r]];return n}function p(e){return"function"==typeof e}function l(e,n,r,t){for(var o in r)p(r[o])?function(r,o){n[r]=function(r){return e=f(t,k),p(r=o(r))&&p(r=r(e))&&(r=r(n)),r&&r!==e&&!r.then&&g(k=u(t,i(e,r),k)),r}}(o,r[o]):l(e[o]||(e[o]={}),n[o]={},r[o],t.concat(o))}function c(e){if(e&&e.props)return e.props.key}function s(e,n,r,t){if("key"===n);else if("style"===n)for(var o in i(t,r=r||{}))e.style[o]=null==r[o]?"":r[o];else{try{e[n]=null==r?"":r}catch(e){}p(r)||(null==r||!1===r?e.removeAttribute(n):e.setAttribute(n,r))}}function a(e,n){if("string"==typeof e)var r=document.createTextNode(e);else{var r=(n=n||"svg"===e.type)?document.createElementNS("http://www.w3.org/2000/svg",e.type):document.createElement(e.type);e.props.oncreate&&N.push(function(){e.props.oncreate(r)});for(var t=0;t<e.children.length;t++)r.appendChild(a(e.children[t],n));for(var t in e.props)s(r,t,e.props[t])}return r}function d(e,n,r){for(var t in i(n,r)){var o=r[t],u="value"===t||"checked"===t?e[t]:n[t];o!==u&&s(e,t,o,u)}r.onupdate&&N.push(function(){r.onupdate(e,n)})}function h(e,n,r){function t(){e.removeChild(n)}r&&r.onremove?r.onremove(n,t):t()}function v(e,n,r,t,o,i){if(r===t);else if(null==r)n=e.insertBefore(a(t,o),n);else if(null!=t.type&&t.type===r.type){d(n,r.props,t.props),o=o||"svg"===t.type;for(var u=t.children.length,f=r.children.length,p={},l=[],s={},y=0;y<f;y++){var g=l[y]=n.childNodes[y],m=r.children[y],w=c(m);null!=w&&(p[w]=[g,m])}for(var y=0,b=0;b<u;){var g=l[y],m=r.children[y],N=t.children[b],w=c(m);if(s[w])y++;else{var k=c(N),x=p[k]||[];null==k?(null==w&&(v(n,g,m,N,o),b++),y++):(w===k?(v(n,x[0],x[1],N,o),y++):x[0]?(n.insertBefore(x[0],g),v(n,x[0],x[1],N,o)):v(n,g,null,N,o),b++,s[k]=N)}}for(;y<f;){var m=r.children[y],w=c(m);null==w&&h(n,l[y],m.props),y++}for(var y in p){var x=p[y],A=x[1];s[A.props.key]||h(n,x[0],A.props)}}else n&&t!==n.nodeValue&&("string"==typeof t&&"string"==typeof r?n.nodeValue=t:(n=e.insertBefore(a(t,o),i=n),h(e,i,r.props)));return n}function y(r){for(m=!m,p(r=e.view(k))&&(r=r(x)),m||(w=v(n,w,b,b=r));r=N.pop();)r()}function g(){e.view&&!m&&setTimeout(y,m=!m)}var m,w=(n=n||document.body).children[0],b=t(w,[].map),N=[],k=e.state||{},x={};return g(l(k,x,e.actions,[])),x}function r(e,n){for(var r,t=[],o=[],i=arguments.length;i-- >2;)t.push(arguments[i]);for(;t.length;)if(Array.isArray(r=t.pop()))for(i=r.length;i--;)t.push(r[i]);else null==r||!0===r||!1===r||o.push("number"==typeof r?r+="":r);return"string"==typeof e?{type:e,props:n||{},children:o}:e(n||{},o)}e.app=n,e.h=r});
//# sourceMappingURL=hyperapp.js.map

@@ -44,3 +44,3 @@ export as namespace Hyperapp

* @memberOf [VDOM]
*/
*/
export function h<Props>(

@@ -54,20 +54,2 @@ type: Component<Props> | string,

/** The application state.
*
* @memberOf [App]
*/
export interface State {}
export interface Update<State extends Hyperapp.State> {
(value: Partial<State>): void
}
/** Thunk that may be returned by an action.
*
* @memberOf [App]
*/
export interface Thunk<State extends Hyperapp.State> {
(update: Update<State>): {} | null | void
}
/** The result of an action.

@@ -77,40 +59,12 @@ *

*/
export type ActionResult<State extends Hyperapp.State> =
| Partial<State>
| Thunk<State>
| {}
| null
| void
export type ActionResult<State> = Partial<State> | Promise<any> | null | void
/** The interface for a single action (exposed when calling actions).
*
* @memberOf [App]
*/
export interface Action<State extends Hyperapp.State, Data> {
(data: Data): ActionResult<State>
}
export type MyAction<State, Actions> = (
data: any
) =>
| ((
state: State
) => ((actions: Actions) => ActionResult<State>) | ActionResult<State>)
| ActionResult<State>
/** The interface for actions (exposed when calling actions).
*
* @memberOf [App]
*/
export interface Actions<
State extends Hyperapp.State & Partial<Record<keyof Actions<State>, any>>
> {
[action: string]:
| Actions<State[keyof Action<State, any>]>
| Action<State, any>
}
/** The interface for a single action (exposed when implementing actions).
*
* @memberOf [App]
*/
export interface InternalAction<
State extends Hyperapp.State,
Actions extends Hyperapp.Actions<State>
> {
(state: State, actions: Actions, data: any): ActionResult<State>
}
/** The interface for actions (exposed when implementing actions).

@@ -120,9 +74,4 @@ *

*/
export type InternalActions<
State extends Hyperapp.State & Partial<Record<keyof Actions, any>>,
Actions extends Hyperapp.Actions<State>
> = {
[P in keyof Actions]:
| InternalAction<State, Actions>
| InternalActions<State[P], Actions[P] & Hyperapp.Actions<State[P]>>
export type MyActions<State, Actions> = {
[P in keyof Actions]: MyAction<State, Actions> | MyActions<any, Actions[P]>
}

@@ -134,50 +83,6 @@

*/
export interface View<
State extends Hyperapp.State,
Actions extends Hyperapp.Actions<State>
> {
export interface View<State, Actions> {
(state: State, actions: Actions): VNode<{}>
}
/** Definition for a single module: a self-contained set of actions that operates on a state tree.
*
* OwnState and OwnActions may be set to ensure that the initial state and all actions are implemented.
*
* @param State The full state of the module including sub-modules
* @param Actions The actions of the module including sub-modules
* @param OwnState Optional, if set, the state of this module excluding sub-modules
* defaults to partial state
* @param OwnActions Optional, if set, the actions of this module excluding sub-modules
* defaults to partial actions
*
* @memberOf [App]
*/
export interface Module<
State extends Hyperapp.State & Record<keyof Actions, any>,
Actions extends Hyperapp.Actions<State>,
OwnState = Partial<State>,
OwnActions = Partial<Actions>
> {
state?: OwnState
actions?: InternalActions<State, OwnActions & Hyperapp.Actions<State>>
modules?: Modules<
Partial<State> & Record<keyof Partial<Actions>, any>,
Partial<Actions> & Hyperapp.Actions<State>
>
}
/** The map of modules indexed by state slice.
*
* @memberOf [App]
*/
export type Modules<
State extends Hyperapp.State & Record<keyof Actions, any>,
Actions extends Hyperapp.Actions<State>
> = {
[A in keyof Actions]?: Module<
State[A],
Actions[A] & Hyperapp.Actions<State[A]>
>
}
/** The props object that serves as an input to app().

@@ -187,36 +92,20 @@ *

* @param Actions The actions of the module including sub-modules
* @param OwnState Optional, if set, the state of this module excluding sub-modules
* defaults to partial state
* @param OwnActions Optional, if set, the actions of this module excluding sub-modules
* defaults to partial actions
*
* @memberOf [App]
*/
export interface AppProps<
State extends Hyperapp.State & Record<keyof Actions, any>,
Actions extends Hyperapp.Actions<State>,
OwnState = Partial<State>,
OwnActions = Partial<Actions>
> extends Module<State, Actions, OwnState, OwnActions> {
export interface AppProps<State, Actions> {
state?: State
view?: View<State, Actions>
actions?: MyActions<State, Actions>
}
/** The app() function, main entry point of Hyperapp's API.
/** The app() function, entry point of Hyperapp's API.
*
* @param State The full state of the module including sub-modules
* @param Actions The actions of the module including sub-modules
* @param OwnState Optional, if set, the state of this module excluding sub-modules
* defaults to partial state
* @param OwnActions Optional, if set, the actions of this module excluding sub-modules
* defaults to partial actions
*
* @memberOf [App]
*/
export function app<
State extends Hyperapp.State & Record<keyof Actions, any>,
Actions extends Hyperapp.Actions<State>,
OwnState = Partial<State>,
OwnActions = Partial<Actions>
>(
app: AppProps<State, Actions, OwnState, OwnActions>,
export function app<State, Actions>(
app: AppProps<State, Actions>,
container?: HTMLElement | null

@@ -223,0 +112,0 @@ ): Actions

{
"name": "hyperapp",
"description": "1 KB JavaScript library for building frontend applications.",
"version": "0.16.0",
"version": "0.16.1",
"main": "dist/hyperapp.js",

@@ -20,3 +20,2 @@ "jsnext:main": "src/index.js",

"elm",
"jsx",
"vdom"

@@ -30,3 +29,3 @@ ],

"prepare": "npm run build",
"format": "prettier --semi false --write 'src/**/*.js' '{,test/ts/}*.{ts,tsx}'",
"format": "prettier --semi false --write \"src/**/*.js\" \"{,test/ts/}*.{ts,tsx}\"",
"release": "npm run build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"

@@ -38,9 +37,9 @@ },

"devDependencies": {
"babel-preset-env": "1.6.1",
"babel-preset-env": "^1.6.1",
"jest": "^21.2.1",
"prettier": "~1.7.4",
"rollup": "^0.50.0",
"typescript": "~2.5.2",
"prettier": "^1.8.2",
"rollup": "^0.51.2",
"typescript": "^2.6.1",
"uglify-js": "^2.7.5"
}
}

@@ -26,3 +26,3 @@ # [Hyperapp](https://codepen.io/hyperapp)

},
view: (state, actions) =>
view: state => actions =>
<main>

@@ -34,4 +34,4 @@ <h1>{state.count}</h1>

actions: {
down: state => ({ count: state.count - 1 }),
up: state => ({ count: state.count + 1 })
down: () => state => ({ count: state.count - 1 }),
up: () => state => ({ count: state.count + 1 })
}

@@ -38,0 +38,0 @@ })

@@ -1,12 +0,10 @@

export { h, app }
function app(props, container) {
export function app(props, container) {
var lock
var root = (container = container || document.body).children[0]
var node = vnode(root, [].map)
var appState = {}
var lifecycle = []
var appState = props.state || {}
var appActions = {}
var lifecycle = []
var patchLock
repaint(init(appState, appActions, props, []))
repaint(init(appState, appActions, props.actions, []))

@@ -30,54 +28,9 @@ return appActions

function repaint() {
if (props.view && !patchLock) {
setTimeout(render, (patchLock = !patchLock))
function set(to, from) {
for (var i in from) {
to[i] = from[i]
}
return to
}
function render(next) {
patchLock = !patchLock
if ((next = props.view(appState, appActions)) && !patchLock) {
root = patch(container, root, node, (node = next))
}
while ((next = lifecycle.pop())) next()
}
function init(state, actions, from, path) {
var modules = from.modules
initDeep(state, actions, from.actions, path)
set(state, from.state)
for (var i in modules) {
init((state[i] = {}), (actions[i] = {}), modules[i], path.concat(i))
}
}
function initDeep(state, actions, from, path) {
Object.keys(from || {}).map(function(key) {
if (typeof from[key] === "function") {
actions[key] = function(data) {
var result = from[key]((state = get(path, appState)), actions)
if (typeof result === "function") {
result = result(data)
}
if (result && result !== state && !result.then) {
repaint((appState = setDeep(path, merge(state, result), appState)))
}
return result
}
} else {
initDeep(
state[key] || (state[key] = {}),
(actions[key] = {}),
from[key],
path.concat(key)
)
}
})
}
function merge(to, from) {

@@ -87,12 +40,5 @@ return set(set({}, to), from)

function set(to, from) {
for (var i in from) {
to[i] = from[i]
}
return to
}
function setDeep(path, value, from) {
var to = {}
return path.length === 0
return 0 === path.length
? value

@@ -113,2 +59,65 @@ : ((to[path[0]] =

function isFunction(any) {
return "function" === typeof any
}
function init(state, actions, from, path) {
for (var key in from) {
isFunction(from[key])
? (function(key, action) {
actions[key] = function(data) {
state = get(path, appState)
if (
isFunction((data = action(data))) &&
isFunction((data = data(state)))
) {
data = data(actions)
}
if (data && data !== state && !data.then) {
repaint(
(appState = setDeep(path, merge(state, data), appState))
)
}
return data
}
})(key, from[key])
: init(
state[key] || (state[key] = {}),
(actions[key] = {}),
from[key],
path.concat(key)
)
}
}
function getKey(node) {
if (node && node.props) {
return node.props.key
}
}
function setElementProp(element, name, value, oldValue) {
if (name === "key") {
} else if (name === "style") {
for (var i in merge(oldValue, (value = value || {}))) {
element.style[i] = null == value[i] ? "" : value[i]
}
} else {
try {
element[name] = null == value ? "" : value
} catch (_) {}
if (!isFunction(value)) {
if (null == value || false === value) {
element.removeAttribute(name)
} else {
element.setAttribute(name, value)
}
}
}
}
function createElement(node, isSVG) {

@@ -139,23 +148,2 @@ if (typeof node === "string") {

function setElementProp(element, name, value, oldValue) {
if (name === "key") {
} else if (name === "style") {
for (var name in merge(oldValue, (value = value || {}))) {
element.style[name] = value[name] || ""
}
} else {
try {
element[name] = null == value ? "" : value
} catch (_) {}
if (typeof value !== "function") {
if (null == value || false === value) {
element.removeAttribute(name)
} else {
element.setAttribute(name, value)
}
}
}
}
function updateElement(element, oldProps, props) {

@@ -179,2 +167,6 @@ for (var i in merge(oldProps, props)) {

function removeElement(parent, element, props) {
function done() {
parent.removeChild(element)
}
if (props && props.onremove) {

@@ -185,17 +177,7 @@ props.onremove(element, done)

}
function done() {
parent.removeChild(element)
}
}
function getKey(node) {
if (node && node.props) {
return node.props.key
}
}
function patch(parent, element, oldNode, node, isSVG, nextSibling) {
if (oldNode === node) {
} else if (oldNode == null) {
} else if (null == oldNode) {
element = parent.insertBefore(createElement(node, isSVG), element)

@@ -292,5 +274,25 @@ } else if (node.type != null && node.type === oldNode.type) {

}
function render(next) {
lock = !lock
if (isFunction((next = props.view(appState)))) {
next = next(appActions)
}
if (!lock) {
root = patch(container, root, node, (node = next))
}
while ((next = lifecycle.pop())) next()
}
function repaint() {
if (props.view && !lock) {
setTimeout(render, (lock = !lock))
}
}
}
function h(type, props) {
export function h(type, props) {
var node

@@ -309,3 +311,4 @@ var stack = []

}
} else if (node != null && node !== true && node !== false) {
} else if (null == node || node === true || node === false) {
} else {
children.push(typeof node === "number" ? (node = node + "") : node)

@@ -312,0 +315,0 @@ }

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc