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

literaljs

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literaljs - npm Package Compare versions

Comparing version 2.2.3 to 2.3.0

2

build/index.js

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

var e={},t=[],n=function(t){return e=Object.assign({},e,t)},r=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();i(e,n,{oldState:r.oldState,newState:r.newState})})},i=function(e,t,n){var r=d(t(),n.oldState),i=d(t(),n.newState);return v(e,i,r)},o=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?o(e[n],t):t.push(e[n]);return t},d=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=d(e.children[n],t);return e},a=function(e,t){if(void 0===t&&(t=!0),"object"!=typeof e)return document.createTextNode(e);for(var n=document.createElement(e.element),r=0,i=Object.entries(e);r<i.length;r+=1){var o=i[r],d=o[0],l=o[1];if("text"===d&&c(l,n),"events"===d&&u(l,n,t),["children","element","text","events"].includes(d)||n.setAttribute(d,l),"children"===d)for(var f=0;f<l.length;f++)n.appendChild(a(l[f]))}return n},c=function(e,t){var n=document.createTextNode(e);t.appendChild(n)},u=function(e,t,n){var r=["mounted","unmounted","updated"],i=function(e){n&&"mounted"===e.type&&e.action(),n||"updated"!==e.type||e.action()};if(Array.isArray(e))for(var o=0;o<e.length;o++)r.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),i(e[o]);else r.includes(e.type)||t.addEventListener(e.type,e.action),i(e)},l=function(t){return void 0===t&&(t=e),Object.assign({},t)},f=function(n){var r=l(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},v=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(a(t),i):void 0===n?e.appendChild(a(t)):0===n&&e.replaceChild(a(t,!1),i);else if(!t&&n)y(n,"unmounted"),e.removeChild(i);else if(t&&(m(i,t,n),p(e,i,t,n),t.children||n.children))for(var o=s(t.children,n.children),d=o.newChildren,c=o.oldChildren,u=0;u<h(d,c);u++)v(i,d[u],c[u],u)}},s=function(e,t){for(var n=[],r=[],i=0;i<h(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},h=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},p=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(a(n,!1),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],c=d[0],u=d[1],l=r[c];if("element"===c||"text"===c)u!==l&&e.replaceChild(a(n,!1),t);else if(!(["children","events","element","text"].includes(c)||l&&u===l))return y(n,"updated"),t.setAttribute(name,value)}},m=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r];t[o[0]]||e.removeAttribute(o[1])}},y=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};module.exports={component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({getState:function(){return l(r)},setState:f,props:e,methods:t({getState:function(){return l()},setState:f})})}}},render:function(t,i,o){void 0===o&&(o={});var c=document.getElementById(i);n(o),r(c,t);var u=d(t(),e),l=a(u);c.appendChild(l)},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:o(n,[])})}};
var e={},t=[],n=[],r=function(t){return e=Object.assign({},e,t)},i=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();d(e,n,{oldState:r.oldState,newState:r.newState})})},o=function(){var e=function(){for(var e;e=n.pop();)e()};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},d=function(e,t,n){var r=u(t(),n.oldState),i=u(t(),n.newState);return p(e,i,r)},a=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?a(e[n],t):t.push(e[n]);return t},u=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=u(e.children[n],t);return e},c=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,a=Object.entries(e);d<a.length;d+=1){var u=a[d],v=u[0],f=u[1];if("text"===v&&o.appendChild(document.createTextNode(f)),"events"===v&&l(f,o,n,r),["children","element","text","events"].includes(v)||o.setAttribute(v,f),"children"===v)for(var s=0;s<f.length;s++)o.appendChild(c(f[s]))}return o},l=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),v(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),v(e,n,r)},v=function(e,t,r){t&&"mounted"===e.type&&n.push(e.action),t||"updated"!==e.type||n.push(e.action),r&&f()},f=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},s=function(t){return void 0===t&&(t=e),Object.assign({},t)},h=function(n){var r=s(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},p=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(c(t),i):void 0===n?e.appendChild(c(t)):0===n&&e.replaceChild(c(t,{mount:!1}),i);else if(!t&&n)g(n,"unmounted"),e.removeChild(i);else if(t&&(_(i,t,n),E(e,i,t,n),t.children||n.children))for(var o=m(t.children,n.children),d=o.newChildren,a=o.oldChildren,u=0;u<y(d,a);u++)p(i,d[u],a[u],u)}},m=function(e,t){for(var n=[],r=[],i=0;i<y(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},y=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},E=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(c(n,{mount:!1}),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],a=d[0],u=d[1],l=r[a];if("element"===a||"text"===a)u!==l&&e.replaceChild(c(n,{mount:!1}),t);else if(!(["children","events","element","text"].includes(a)||l&&u===l))return g(n,"updated"),t.setAttribute(name,value)}},_=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(g(t,"updated"),e.removeAttribute(d))}},g=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};module.exports={component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:s(r),getState:s,setState:h,props:e,methods:t({getState:s,setState:h})})}}},render:function(t,n,d){void 0===d&&(d={});var a=document.getElementById(n);r(d),i(a,t);var l=u(t(),e),v=c(l,{initial:!0});a.appendChild(v),o()},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:a(n,[])})}};
//# sourceMappingURL=index.js.map

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

var e={},t=[],n=function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:a(n,[])})},r=function(t,n,r){void 0===r&&(r={});var d=document.getElementById(n);i(r),o(d,t);var a=c(t(),e),l=u(a);d.appendChild(l)},i=function(t){return e=Object.assign({},e,t)},o=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();d(e,n,{oldState:r.oldState,newState:r.newState})})},d=function(e,t,n){var r=c(t(),n.oldState),i=c(t(),n.newState);return p(e,i,r)},a=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?a(e[n],t):t.push(e[n]);return t},c=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=c(e.children[n],t);return e},u=function(e,t){if(void 0===t&&(t=!0),"object"!=typeof e)return document.createTextNode(e);for(var n=document.createElement(e.element),r=0,i=Object.entries(e);r<i.length;r+=1){var o=i[r],d=o[0],a=o[1];if("text"===d&&l(a,n),"events"===d&&f(a,n,t),["children","element","text","events"].includes(d)||n.setAttribute(d,a),"children"===d)for(var c=0;c<a.length;c++)n.appendChild(u(a[c]))}return n},l=function(e,t){var n=document.createTextNode(e);t.appendChild(n)},f=function(e,t,n){var r=["mounted","unmounted","updated"],i=function(e){n&&"mounted"===e.type&&e.action(),n||"updated"!==e.type||e.action()};if(Array.isArray(e))for(var o=0;o<e.length;o++)r.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),i(e[o]);else r.includes(e.type)||t.addEventListener(e.type,e.action),i(e)},v=function(t){return void 0===t&&(t=e),Object.assign({},t)},s=function(n){var r=v(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},h=function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({getState:function(){return v(r)},setState:s,props:e,methods:t({getState:function(){return v()},setState:s})})}}},p=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(u(t),i):void 0===n?e.appendChild(u(t)):0===n&&e.replaceChild(u(t,!1),i);else if(!t&&n)A(n,"unmounted"),e.removeChild(i);else if(t&&(b(i,t,n),g(e,i,t,n),t.children||n.children))for(var o=m(t.children,n.children),d=o.newChildren,a=o.oldChildren,c=0;c<y(d,a);c++)p(i,d[c],a[c],c)}},m=function(e,t){for(var n=[],r=[],i=0;i<y(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},y=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},g=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(u(n,!1),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],a=d[0],c=d[1],l=r[a];if("element"===a||"text"===a)c!==l&&e.replaceChild(u(n,!1),t);else if(!(["children","events","element","text"].includes(a)||l&&c===l))return A(n,"updated"),t.setAttribute(name,value)}},b=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r];t[o[0]]||e.removeAttribute(o[1])}},A=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};export default{component:h,render:r,h:n};export{n as h,r as render,h as component};
var e={},t=[],n=[],r=function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:c(n,[])})},i=function(t,n,r){void 0===r&&(r={});var i=document.getElementById(n);o(r),d(i,t);var u=l(t(),e),c=v(u,{initial:!0});i.appendChild(c),a()},o=function(t){return e=Object.assign({},e,t)},d=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();u(e,n,{oldState:r.oldState,newState:r.newState})})},a=function(){var e=function(){for(var e;e=n.pop();)e()};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},u=function(e,t,n){var r=l(t(),n.oldState),i=l(t(),n.newState);return E(e,i,r)},c=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?c(e[n],t):t.push(e[n]);return t},l=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=l(e.children[n],t);return e},v=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,a=Object.entries(e);d<a.length;d+=1){var u=a[d],c=u[0],l=u[1];if("text"===c&&o.appendChild(document.createTextNode(l)),"events"===c&&f(l,o,n,r),["children","element","text","events"].includes(c)||o.setAttribute(c,l),"children"===c)for(var s=0;s<l.length;s++)o.appendChild(v(l[s]))}return o},f=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),s(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),s(e,n,r)},s=function(e,t,r){t&&"mounted"===e.type&&n.push(e.action),t||"updated"!==e.type||n.push(e.action),r&&h()},h=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},p=function(t){return void 0===t&&(t=e),Object.assign({},t)},m=function(n){var r=p(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},y=function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:p(r),getState:p,setState:m,props:e,methods:t({getState:p,setState:m})})}}},E=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(v(t),i):void 0===n?e.appendChild(v(t)):0===n&&e.replaceChild(v(t,{mount:!1}),i);else if(!t&&n)w(n,"unmounted"),e.removeChild(i);else if(t&&(L(i,t,n),C(e,i,t,n),t.children||n.children))for(var o=_(t.children,n.children),d=o.newChildren,a=o.oldChildren,u=0;u<g(d,a);u++)E(i,d[u],a[u],u)}},_=function(e,t){for(var n=[],r=[],i=0;i<g(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},g=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},C=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(v(n,{mount:!1}),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],a=d[0],u=d[1],c=r[a];if("element"===a||"text"===a)u!==c&&e.replaceChild(v(n,{mount:!1}),t);else if(!(["children","events","element","text"].includes(a)||c&&u===c))return w(n,"updated"),t.setAttribute(name,value)}},L=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(w(t,"updated"),e.removeAttribute(d))}},w=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};export default{component:y,render:i,h:r};export{r as h,i as render,y as component};
//# sourceMappingURL=index.m.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.literaljs=t()}(this,function(){var e={},t=[],n=function(t){return e=Object.assign({},e,t)},r=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();i(e,n,{oldState:r.oldState,newState:r.newState})})},i=function(e,t,n){var r=d(t(),n.oldState),i=d(t(),n.newState);return v(e,i,r)},o=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?o(e[n],t):t.push(e[n]);return t},d=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=d(e.children[n],t);return e},a=function(e,t){if(void 0===t&&(t=!0),"object"!=typeof e)return document.createTextNode(e);for(var n=document.createElement(e.element),r=0,i=Object.entries(e);r<i.length;r+=1){var o=i[r],d=o[0],f=o[1];if("text"===d&&c(f,n),"events"===d&&u(f,n,t),["children","element","text","events"].includes(d)||n.setAttribute(d,f),"children"===d)for(var l=0;l<f.length;l++)n.appendChild(a(f[l]))}return n},c=function(e,t){var n=document.createTextNode(e);t.appendChild(n)},u=function(e,t,n){var r=["mounted","unmounted","updated"],i=function(e){n&&"mounted"===e.type&&e.action(),n||"updated"!==e.type||e.action()};if(Array.isArray(e))for(var o=0;o<e.length;o++)r.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),i(e[o]);else r.includes(e.type)||t.addEventListener(e.type,e.action),i(e)},f=function(t){return void 0===t&&(t=e),Object.assign({},t)},l=function(n){var r=f(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},v=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(a(t),i):void 0===n?e.appendChild(a(t)):0===n&&e.replaceChild(a(t,!1),i);else if(!t&&n)y(n,"unmounted"),e.removeChild(i);else if(t&&(m(i,t,n),p(e,i,t,n),t.children||n.children))for(var o=s(t.children,n.children),d=o.newChildren,c=o.oldChildren,u=0;u<h(d,c);u++)v(i,d[u],c[u],u)}},s=function(e,t){for(var n=[],r=[],i=0;i<h(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},h=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},p=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(a(n,!1),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],c=d[0],u=d[1],f=r[c];if("element"===c||"text"===c)u!==f&&e.replaceChild(a(n,!1),t);else if(!(["children","events","element","text"].includes(c)||f&&u===f))return y(n,"updated"),t.setAttribute(name,value)}},m=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r];t[o[0]]||e.removeAttribute(o[1])}},y=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};return{component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({getState:function(){return f(r)},setState:l,props:e,methods:t({getState:function(){return f()},setState:l})})}}},render:function(t,i,o){void 0===o&&(o={});var c=document.getElementById(i);n(o),r(c,t);var u=d(t(),e),f=a(u);c.appendChild(f)},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:o(n,[])})}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.literaljs=t()}(this,function(){var e={},t=[],n=[],r=function(t){return e=Object.assign({},e,t)},i=function(e,n){window.addEventListener("__LITERAL_UPDATE__",function(){var r=t.pop();d(e,n,{oldState:r.oldState,newState:r.newState})})},o=function(){var e=function(){for(var e;e=n.pop();)e()};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},d=function(e,t,n){var r=u(t(),n.oldState),i=u(t(),n.newState);return p(e,i,r)},a=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?a(e[n],t):t.push(e[n]);return t},u=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=u(e.children[n],t);return e},c=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,a=Object.entries(e);d<a.length;d+=1){var u=a[d],l=u[0],v=u[1];if("text"===l&&o.appendChild(document.createTextNode(v)),"events"===l&&f(v,o,n,r),["children","element","text","events"].includes(l)||o.setAttribute(l,v),"children"===l)for(var s=0;s<v.length;s++)o.appendChild(c(v[s]))}return o},f=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),l(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),l(e,n,r)},l=function(e,t,r){t&&"mounted"===e.type&&n.push(e.action),t||"updated"!==e.type||n.push(e.action),r&&v()},v=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},s=function(t){return void 0===t&&(t=e),Object.assign({},t)},h=function(n){var r=s(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},p=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?e.insertBefore(c(t),i):void 0===n?e.appendChild(c(t)):0===n&&e.replaceChild(c(t,{mount:!1}),i);else if(!t&&n)g(n,"unmounted"),e.removeChild(i);else if(t&&(_(i,t,n),E(e,i,t,n),t.children||n.children))for(var o=m(t.children,n.children),d=o.newChildren,a=o.oldChildren,u=0;u<y(d,a);u++)p(i,d[u],a[u],u)}},m=function(e,t){for(var n=[],r=[],i=0;i<y(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},y=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},E=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&e.replaceChild(c(n,{mount:!1}),t);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],a=d[0],u=d[1],f=r[a];if("element"===a||"text"===a)u!==f&&e.replaceChild(c(n,{mount:!1}),t);else if(!(["children","events","element","text"].includes(a)||f&&u===f))return g(n,"updated"),t.setAttribute(name,value)}},_=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(g(t,"updated"),e.removeAttribute(d))}},g=function(e,t){if(e.events){var n=e.events;if(Array.isArray(n))for(var r=0;r<n.length;r++)n[r].type===t&&n.action();else n.type===t&&n.action()}};return{component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:s(r),getState:s,setState:h,props:e,methods:t({getState:s,setState:h})})}}},render:function(t,n,d){void 0===d&&(d={});var a=document.getElementById(n);r(d),i(a,t);var f=u(t(),e),l=c(f,{initial:!0});a.appendChild(l),o()},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:a(n,[])})}}});
//# sourceMappingURL=index.umd.js.map
{
"name": "literaljs",
"version": "2.2.3",
"version": "2.3.0",
"description": "~1kb JavaScript library for building user interfaces.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -8,5 +8,5 @@ # LiteralJS

Build output to build:
1.33 kB: index.js
1.36 kB: index.m.js
1.38 kB: index.umd.js
1.47 kB: index.js
1.49 kB: index.m.js
1.52 kB: index.umd.js
```

@@ -35,3 +35,6 @@ ### [Features and stuff](#features)

- [methods](#component-methods)
- [getState](#methods-getState)
- [setState](#methods-setState)
- [render](#component-render)
- [state](#state)
- [getState](#getstate)

@@ -87,12 +90,9 @@ - [setState](#setstate)

const Foo = component({
render: ({ getState, setState }) => (
render: ({ state, getState, setState }) => (
<div class='container'>
This is the Count: {getState().count}
This is the Count: {state.count}
<button
events={{
type: 'click',
action: () => {
var state = getState();
setState({ count: state.count + 1 });
}
action: () => setState({ count: getState().count + 1 })
}}>

@@ -112,6 +112,6 @@ Click Me!

const Foo = component({
render: ({ getState, setState }) =>
render: ({ state, getState, setState }) =>
h('div', {
class: 'container',
text: `This is the Count: ${getState().count}`
text: `This is the Count: ${state.count}`
}, [

@@ -121,6 +121,3 @@ h('button', {

type: 'click',
action: () => {
var state = getState();
setState({ count: state.count + 1 });
}
action: () => setState({ count: getState().count + 1 })
}

@@ -139,6 +136,6 @@ })

const Foo = component({
render: ({ getState, setState }) => ({
render: ({ state, getState, setState }) => ({
element: 'div',
class: 'container',
text: `This is the Count: ${getState().count}`,
text: `This is the Count: ${state.count}`,
children: [

@@ -150,6 +147,3 @@ {

type: 'click',
action: () => {
var state = getState();
setState({ count: state.count + 1 });
}
action: () => setState({ count: getState().count + 1 })
}

@@ -180,3 +174,3 @@ }

const Bar = component({
render: ({ getState, setState, props }) => (
render: ({ props }) => (
<p>Total: {props.total}</p>

@@ -187,3 +181,3 @@ )

const Foo = component({
render: ({ getState, setState }) => (
render: () => (
<div>{Bar({ total: 9 })}</div>

@@ -198,2 +192,14 @@ )

#### [getState](#methods-getState)
`getState` is a function which is accessible as a property of the `methods` function.
Using the `getState` function will pull the latest state objecty of your application. Once used, the specific state keys are accessible via dot notation.
#### [setState](#methods-setState)
`setState` is a function which is accessible as a property of the `methods` function.
Using the `setState` function will cause the application state to update and diffing to occur.
**Example:**

@@ -204,8 +210,5 @@

methods: ({ getState, setState }) => ({
increase: () => {
const count = getState().count;
setState({ count: count + 1 });
}
increase: () => setState({ count: getState().count + 1 })
}),
render: ({ getState, setState, methods: { increase }}) => (
render: ({ state, getState, setState, methods: { increase }}) => (
<button

@@ -217,3 +220,3 @@ events={{

>
Current Count: {getState().count}
Current Count: {state.count}
</button>

@@ -243,8 +246,5 @@ )

methods: ({ getState, setState }) => ({
increase: () => {
const count = getState().count;
setState({ count: count + 1 });
}
increase: () => setState({ count: getState().count + 1 })
}),
render: ({ getState, setState, methods: { increase }}) => (
render: ({ state, getState, setState, methods: { increase }}) => (
<button

@@ -256,3 +256,3 @@ events={{

>
Current Count: {getState().count}
Current Count: {state.count}
</button>

@@ -267,8 +267,5 @@ )

methods: ({ getState, setState }) => ({
increase: () => {
const count = getState().count;
setState({ count: count + 1 });
}
increase: () => setState({ count: getState().count + 1 })
}),
render: ({ getState, setState, methods: { increase }}) => (
render: ({ state, getState, setState, methods: { increase }}) => (
<button

@@ -286,3 +283,3 @@ events={[

>
Current Count: {getState().count}
Current Count: {state.count}
</button>

@@ -442,3 +439,3 @@ )

To do so, just name the `type` value `unmounted or `mounted` to trigger functions when a DOM node is first placed in the DOM or removed from the DOM.
To do so, just name the `type` value `unmounted`, `updated`, or `mounted` to trigger functions when a DOM node is first placed in the DOM or removed from the DOM.

@@ -458,2 +455,6 @@ **Example:**

{
type: 'updated'
action: () => console.log('I\'m updated!')
},
{
type: 'unmounted'

@@ -473,2 +474,3 @@ action: () => console.log('I\'m off the page!')

- [state](#state)
- [getState](#getstate)

@@ -479,5 +481,10 @@ - [setState](#setstate)

### `state`
The `state` property is an Object of the current state and should only be used within markup and not functions or events.
### `getState`
The `getState` function of the `component`s `render` method will allow you to access the global store of your application.
The `getState` function of the `component`s `render` method will allow you to access the global store of your application within functions and events.

@@ -484,0 +491,0 @@ ### `setState`

@@ -47,23 +47,23 @@ import { render, component, h } from '../src';

// test('Lifecycle Mounted Works Properly', () => {
// const Comp = component({
// render: ({ getState, setState }) =>
// h(
// 'div',
// {
// class: 'container',
// events: {
// type: 'mounted',
// action: () => setState({ count: getState().count + 1 })
// }
// },
// getState().count
// )
// });
test('Lifecycle Mounted Works Properly', () => {
const Comp = component({
render: ({ getState, setState }) =>
h(
'div',
{
class: 'container',
events: {
type: 'mounted',
action: () => setState({ working: !getState().working })
}
},
getState().working
)
});
// render(Comp, 'root', { count: 1 });
render(Comp, 'root', { working: false });
// expect(document.body.innerHTML).toBe(
// '<div id="root"><div class="container">2</div></div>'
// );
// });
expect(document.body.innerHTML).toBe(
'<div id="root"><div class="container">true</div></div>'
);
});

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc