Comparing version 0.5.0 to 0.5.1-beta.1
@@ -9,8 +9,13 @@ import { createRuntime } from 'dom-expressions'; | ||
function shallowDiff(a, b) { | ||
let sa = new Set(a), sb = new Set(b); | ||
return [a.filter(i => !sb.has(i)), (b.filter(i => !sa.has(i)))]; | ||
let sa = new Set(a), | ||
sb = new Set(b); | ||
return [a.filter(i => !sb.has(i)), b.filter(i => !sa.has(i))]; | ||
} | ||
const r = createRuntime({wrap: S.makeComputationNode, root: S.root, cleanup: S.cleanup, sample: S.sample}); | ||
const r = createRuntime({ | ||
wrap: S.makeComputationNode, | ||
root: S.root, | ||
cleanup: S.cleanup, | ||
sample: S.sample | ||
}); | ||
function selectWhen(signal, handler) { | ||
@@ -23,3 +28,4 @@ if (typeof handler === 'string') handler = createHandler(handler); | ||
let marker = start; | ||
while(marker && marker !== end) { | ||
while (marker && marker !== end) { | ||
if (marker.model === model) { | ||
@@ -29,2 +35,3 @@ handler(marker, true); | ||
} | ||
marker = marker.nextSibling; | ||
@@ -35,13 +42,15 @@ } | ||
} | ||
function selectEach(signal, handler) { | ||
if (typeof handler === 'string') handler = createHandler(handler); | ||
let start, end; | ||
S.makeComputationNode(elements => { | ||
const models = signal(), newElements = []; | ||
S.makeComputationNode((elements = []) => { | ||
const models = signal(), | ||
newElements = []; | ||
let marker = start; | ||
while(marker && marker !== end) { | ||
while (marker && marker !== end) { | ||
if (models.indexOf(marker.model) > -1) newElements.push(marker); | ||
marker = marker.nextSibling; | ||
} | ||
const [additions, removals] = shallowDiff(newElements, elements); | ||
@@ -48,0 +57,0 @@ additions.forEach(el => handler(el, true)); |
import { createHyperScript } from 'hyper-dom-expressions'; | ||
import { r } from 'solid-js/dom'; | ||
export { selectEach, selectWhen } from 'solid-js/dom'; | ||
import { r } from './index'; | ||
export { selectEach, selectWhen } from './index'; | ||
@@ -5,0 +5,0 @@ const h = createHyperScript(r); |
import { createHTML } from 'lit-dom-expressions'; | ||
import { r } from 'solid-js/dom'; | ||
export { selectEach, selectWhen } from 'solid-js/dom'; | ||
import { r } from './index'; | ||
export { selectEach, selectWhen } from './index'; | ||
@@ -5,0 +5,0 @@ const html = createHTML(r); |
import S from 's-js'; | ||
const SNODE = Symbol('solid-node'), | ||
SPROXY = Symbol('solid-proxy'); | ||
SPROXY = Symbol('solid-proxy'); | ||
function wrap(value) { return value[SPROXY] || (value[SPROXY] = new Proxy(value, proxyTraps)); } | ||
function wrap(value) { | ||
return value[SPROXY] || (value[SPROXY] = new Proxy(value, proxyTraps)); | ||
} | ||
function isWrappable(obj) { return obj !== null && typeof obj === 'object' && (obj.__proto__ === Object.prototype || Array.isArray(obj)); } | ||
function isWrappable(obj) { | ||
return obj !== null && typeof obj === 'object' && (obj.__proto__ === Object.prototype || Array.isArray(obj)); | ||
} | ||
function unwrap(item) { | ||
let result, unwrapped, v; | ||
if ((result = (item != null) && item._state)) return result; | ||
if (result = item != null && item._state) return result; | ||
if (!isWrappable(item)) return item; | ||
@@ -17,2 +20,3 @@ | ||
if (Object.isFrozen(item)) item = item.slice(0); | ||
for (let i = 0, l = item.length; i < l; i++) { | ||
@@ -25,2 +29,3 @@ v = item[i]; | ||
let keys = Object.keys(item); | ||
for (let i = 0, l = keys.length; i < l; i++) { | ||
@@ -31,2 +36,3 @@ v = item[keys[i]]; | ||
} | ||
return item; | ||
@@ -46,21 +52,29 @@ } | ||
const value = target[property], | ||
wrappable = isWrappable(value); | ||
wrappable = isWrappable(value); | ||
if (S.isListening() && typeof value !== 'function') { | ||
let nodes, node; | ||
if (wrappable && (nodes = getDataNodes(value))) { | ||
node = nodes._self || (nodes._self = S.makeDataNode()); | ||
node = nodes._self || (nodes._self = S.makeDataNode(undefined)); | ||
node.current(); | ||
} | ||
nodes = getDataNodes(target); | ||
node = nodes[property] || (nodes[property] = S.makeDataNode()); | ||
node = nodes[property] || (nodes[property] = S.makeDataNode(undefined)); | ||
node.current(); | ||
} | ||
return wrappable ? wrap(value) : value; | ||
}, | ||
set() { return true; }, | ||
set() { | ||
return true; | ||
}, | ||
deleteProperty() { return true; } | ||
deleteProperty() { | ||
return true; | ||
} | ||
}; | ||
function setProperty(state, property, value) { | ||
@@ -70,6 +84,9 @@ value = unwrap(value); | ||
const notify = Array.isArray(state) || !(property in state); | ||
if (value === void 0) { | ||
delete state[property]; | ||
} else state[property] = value; | ||
let nodes = getDataNodes(state), node; | ||
let nodes = getDataNodes(state), | ||
node; | ||
(node = nodes[property]) && node.next(); | ||
@@ -81,2 +98,3 @@ notify && (node = nodes._self) && node.next(); | ||
const keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i += 1) { | ||
@@ -91,7 +109,9 @@ const key = keys[i]; | ||
let value = path[0]; | ||
if (typeof value === 'function') { | ||
value = value(wrap(current), traversed); | ||
// reconciled | ||
value = value(wrap(current), traversed); // reconciled | ||
if (value === undefined) return; | ||
} | ||
mergeState(current, value); | ||
@@ -102,4 +122,4 @@ return; | ||
const part = path.shift(), | ||
partType = typeof part, | ||
isArray = Array.isArray(current); | ||
partType = typeof part, | ||
isArray = Array.isArray(current); | ||
@@ -118,3 +138,8 @@ if (Array.isArray(part)) { | ||
// Ex. update('data', { from: 3, to: 12, by: 2 }, 'label', l => l + ' !!!'); | ||
const {from = 0, to = current.length - 1, by = 1} = part; | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -130,2 +155,3 @@ updatePath(current, [i].concat(path), traversed.concat([i])); | ||
let value = path[0]; | ||
if (typeof value === 'function') { | ||
@@ -135,2 +161,3 @@ const currentPart = current[part]; | ||
} | ||
if (isWrappable(current[part]) && isWrappable(value) && !Array.isArray(value)) { | ||
@@ -142,4 +169,4 @@ mergeState(current[part], value); | ||
function createState(state = {}) { | ||
state = unwrap(state); | ||
function createState(state) { | ||
state = unwrap(state || {}); | ||
const wrappedState = wrap(state); | ||
@@ -164,4 +191,5 @@ | ||
if (target === previous) return; | ||
if (!isWrappable(target) || (previous == null)) { | ||
(target !== previous) && setProperty(parent, property, target); | ||
if (!isWrappable(target) || previous == null) { | ||
target !== previous && setProperty(parent, property, target); | ||
return; | ||
@@ -171,15 +199,25 @@ } | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || (key && target[0][key] != null))) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal, | ||
temp = new Array(target.length), | ||
newIndices = new Map(); | ||
// skip common prefix and suffix | ||
if (target.length && previous.length && (!merge || key && target[0][key] != null)) { | ||
let i, | ||
j, | ||
start, | ||
end, | ||
newEnd, | ||
item, | ||
newIndicesNext, | ||
keyVal, | ||
temp = new Array(target.length), | ||
newIndices = new Map(); // skip common prefix and suffix | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start][key] === target[start][key]); start++) { | ||
applyState(target[start], previous, start, merge, key); | ||
} | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= 0 && newEnd >= 0 && (previous[end] === target[newEnd] || key && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
temp[newEnd] = previous[end]; | ||
} | ||
// prepare a map of all indices in target | ||
} // prepare a map of all indices in target | ||
newIndicesNext = new Array(newEnd + 1); | ||
for (j = newEnd; j >= start; j--) { | ||
@@ -191,4 +229,5 @@ item = target[j]; | ||
newIndices.set(keyVal, j); | ||
} | ||
// step through all old items to check reuse | ||
} // step through all old items to check reuse | ||
for (i = start; i <= end; i++) { | ||
@@ -198,2 +237,3 @@ item = previous[i]; | ||
j = newIndices.get(keyVal); | ||
if (j !== undefined && j !== -1) { | ||
@@ -204,4 +244,5 @@ temp[j] = previous[i]; | ||
} | ||
} | ||
// set all the new values | ||
} // set all the new values | ||
for (j = start; j < target.length; j++) { | ||
@@ -211,4 +252,3 @@ if (temp.hasOwnProperty(j)) { | ||
applyState(target[j], previous, j, merge, key); | ||
} | ||
else setProperty(previous, j, target[j]); | ||
} else setProperty(previous, j, target[j]); | ||
} | ||
@@ -220,2 +260,3 @@ } else { | ||
} | ||
if (previous.length > target.length) setProperty(previous, 'length', target.length); | ||
@@ -226,14 +267,18 @@ return; | ||
const targetKeys = Object.keys(target); | ||
for (let i = 0, len = targetKeys.length; i < len; i++) { | ||
applyState(target[targetKeys[i]], previous, targetKeys[i], merge, key); | ||
} | ||
const previousKeys = Object.keys(previous); | ||
for (let i = 0, len = previousKeys.length; i < len; i++) { | ||
if (target[previousKeys[i]] === undefined) setProperty(previous, previousKeys[i], undefined); | ||
} | ||
} | ||
} // Diff method for setState | ||
// Diff method for setState | ||
function reconcile(path, options = {}) { | ||
let value; | ||
if (Array.isArray(path)) { | ||
@@ -245,13 +290,20 @@ value = path.pop(); | ||
} else { | ||
path = Array.prototype.slice.call(arguments, 0, -1), | ||
value = arguments[arguments.length - 1]; | ||
path = Array.prototype.slice.call(arguments, 0, -1), value = arguments[arguments.length - 1]; | ||
options = {}; | ||
} | ||
const { merge, key = 'id' } = options; | ||
const { | ||
merge, | ||
key = 'id' | ||
} = options; | ||
return state => { | ||
state = unwrap(state); | ||
if (path) { | ||
for (let i = 0; i < path.length - 1; i += 1) state = state[path[i]]; | ||
applyState(value, state, path[path.length - 1], merge, key); | ||
} else applyState(value, { state }, 'state', merge, key); | ||
} else applyState(value, { | ||
state | ||
}, 'state', merge, key); | ||
}; | ||
@@ -263,10 +315,14 @@ } | ||
let setter; | ||
if (comparator) { | ||
let age = -1; | ||
setter = v => { | ||
if (!comparator(value, v)) { | ||
const time = d.clock().time(); | ||
if (time === age) { | ||
throw new Error(`Conflicting value update: ${v} is not the same as ${value}`); | ||
} | ||
age = time; | ||
@@ -278,7 +334,8 @@ value = v; | ||
} else setter = d.next.bind(d); | ||
return [d.current.bind(d), setter]; | ||
} | ||
function createMemo(fn, seed) { return S(fn, seed); } | ||
function createMemo(fn, seed) { | ||
return S(fn, seed); | ||
} | ||
function createEffect(fn, deps, defer) { | ||
@@ -288,4 +345,9 @@ deps ? S.on(deps, fn, undefined, defer) : S.makeComputationNode(fn); | ||
const { root: createRoot, cleanup: onCleanup, sample, freeze } = S; | ||
const { | ||
root: createRoot, | ||
cleanup: onCleanup, | ||
sample, | ||
freeze | ||
} = S; | ||
export { createEffect, createMemo, createRoot, createSignal, createState, freeze, onCleanup, reconcile, sample, unwrap }; |
@@ -5,3 +5,4 @@ { | ||
"module": "../dist/dom.js", | ||
"types": "../types/dom/index.d.ts", | ||
"sideEffects": false | ||
} |
@@ -5,3 +5,4 @@ { | ||
"module": "../dist/h.js", | ||
"types": "../types/dom/h.d.ts", | ||
"sideEffects": false | ||
} |
@@ -5,3 +5,4 @@ { | ||
"module": "../dist/html.js", | ||
"types": "../types/dom/html.d.ts", | ||
"sideEffects": false | ||
} |
@@ -15,8 +15,13 @@ 'use strict'; | ||
function shallowDiff(a, b) { | ||
let sa = new Set(a), sb = new Set(b); | ||
return [a.filter(i => !sb.has(i)), (b.filter(i => !sa.has(i)))]; | ||
let sa = new Set(a), | ||
sb = new Set(b); | ||
return [a.filter(i => !sb.has(i)), b.filter(i => !sa.has(i))]; | ||
} | ||
const r = domExpressions.createRuntime({wrap: S.makeComputationNode, root: S.root, cleanup: S.cleanup, sample: S.sample}); | ||
const r = domExpressions.createRuntime({ | ||
wrap: S.makeComputationNode, | ||
root: S.root, | ||
cleanup: S.cleanup, | ||
sample: S.sample | ||
}); | ||
function selectWhen(signal, handler) { | ||
@@ -29,3 +34,4 @@ if (typeof handler === 'string') handler = createHandler(handler); | ||
let marker = start; | ||
while(marker && marker !== end) { | ||
while (marker && marker !== end) { | ||
if (marker.model === model) { | ||
@@ -35,2 +41,3 @@ handler(marker, true); | ||
} | ||
marker = marker.nextSibling; | ||
@@ -41,13 +48,15 @@ } | ||
} | ||
function selectEach(signal, handler) { | ||
if (typeof handler === 'string') handler = createHandler(handler); | ||
let start, end; | ||
S.makeComputationNode(elements => { | ||
const models = signal(), newElements = []; | ||
S.makeComputationNode((elements = []) => { | ||
const models = signal(), | ||
newElements = []; | ||
let marker = start; | ||
while(marker && marker !== end) { | ||
while (marker && marker !== end) { | ||
if (models.indexOf(marker.model) > -1) newElements.push(marker); | ||
marker = marker.nextSibling; | ||
} | ||
const [additions, removals] = shallowDiff(newElements, elements); | ||
@@ -54,0 +63,0 @@ additions.forEach(el => handler(el, true)); |
@@ -6,5 +6,5 @@ 'use strict'; | ||
var hyperDomExpressions = require('hyper-dom-expressions'); | ||
var dom = require('solid-js/dom'); | ||
var index = require('./index'); | ||
const h = hyperDomExpressions.createHyperScript(dom.r); | ||
const h = hyperDomExpressions.createHyperScript(index.r); | ||
@@ -14,3 +14,3 @@ Object.defineProperty(exports, 'selectEach', { | ||
get: function () { | ||
return dom.selectEach; | ||
return index.selectEach; | ||
} | ||
@@ -21,5 +21,5 @@ }); | ||
get: function () { | ||
return dom.selectWhen; | ||
return index.selectWhen; | ||
} | ||
}); | ||
exports.h = h; |
@@ -6,5 +6,5 @@ 'use strict'; | ||
var litDomExpressions = require('lit-dom-expressions'); | ||
var dom = require('solid-js/dom'); | ||
var index = require('./index'); | ||
const html = litDomExpressions.createHTML(dom.r); | ||
const html = litDomExpressions.createHTML(index.r); | ||
@@ -14,3 +14,3 @@ Object.defineProperty(exports, 'selectEach', { | ||
get: function () { | ||
return dom.selectEach; | ||
return index.selectEach; | ||
} | ||
@@ -21,5 +21,5 @@ }); | ||
get: function () { | ||
return dom.selectWhen; | ||
return index.selectWhen; | ||
} | ||
}); | ||
exports.html = html; |
150
lib/solid.js
@@ -10,11 +10,14 @@ 'use strict'; | ||
const SNODE = Symbol('solid-node'), | ||
SPROXY = Symbol('solid-proxy'); | ||
SPROXY = Symbol('solid-proxy'); | ||
function wrap(value) { return value[SPROXY] || (value[SPROXY] = new Proxy(value, proxyTraps)); } | ||
function wrap(value) { | ||
return value[SPROXY] || (value[SPROXY] = new Proxy(value, proxyTraps)); | ||
} | ||
function isWrappable(obj) { return obj !== null && typeof obj === 'object' && (obj.__proto__ === Object.prototype || Array.isArray(obj)); } | ||
function isWrappable(obj) { | ||
return obj !== null && typeof obj === 'object' && (obj.__proto__ === Object.prototype || Array.isArray(obj)); | ||
} | ||
function unwrap(item) { | ||
let result, unwrapped, v; | ||
if ((result = (item != null) && item._state)) return result; | ||
if (result = item != null && item._state) return result; | ||
if (!isWrappable(item)) return item; | ||
@@ -24,2 +27,3 @@ | ||
if (Object.isFrozen(item)) item = item.slice(0); | ||
for (let i = 0, l = item.length; i < l; i++) { | ||
@@ -32,2 +36,3 @@ v = item[i]; | ||
let keys = Object.keys(item); | ||
for (let i = 0, l = keys.length; i < l; i++) { | ||
@@ -38,2 +43,3 @@ v = item[keys[i]]; | ||
} | ||
return item; | ||
@@ -53,21 +59,29 @@ } | ||
const value = target[property], | ||
wrappable = isWrappable(value); | ||
wrappable = isWrappable(value); | ||
if (S.isListening() && typeof value !== 'function') { | ||
let nodes, node; | ||
if (wrappable && (nodes = getDataNodes(value))) { | ||
node = nodes._self || (nodes._self = S.makeDataNode()); | ||
node = nodes._self || (nodes._self = S.makeDataNode(undefined)); | ||
node.current(); | ||
} | ||
nodes = getDataNodes(target); | ||
node = nodes[property] || (nodes[property] = S.makeDataNode()); | ||
node = nodes[property] || (nodes[property] = S.makeDataNode(undefined)); | ||
node.current(); | ||
} | ||
return wrappable ? wrap(value) : value; | ||
}, | ||
set() { return true; }, | ||
set() { | ||
return true; | ||
}, | ||
deleteProperty() { return true; } | ||
deleteProperty() { | ||
return true; | ||
} | ||
}; | ||
function setProperty(state, property, value) { | ||
@@ -77,6 +91,9 @@ value = unwrap(value); | ||
const notify = Array.isArray(state) || !(property in state); | ||
if (value === void 0) { | ||
delete state[property]; | ||
} else state[property] = value; | ||
let nodes = getDataNodes(state), node; | ||
let nodes = getDataNodes(state), | ||
node; | ||
(node = nodes[property]) && node.next(); | ||
@@ -88,2 +105,3 @@ notify && (node = nodes._self) && node.next(); | ||
const keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i += 1) { | ||
@@ -98,7 +116,9 @@ const key = keys[i]; | ||
let value = path[0]; | ||
if (typeof value === 'function') { | ||
value = value(wrap(current), traversed); | ||
// reconciled | ||
value = value(wrap(current), traversed); // reconciled | ||
if (value === undefined) return; | ||
} | ||
mergeState(current, value); | ||
@@ -109,4 +129,4 @@ return; | ||
const part = path.shift(), | ||
partType = typeof part, | ||
isArray = Array.isArray(current); | ||
partType = typeof part, | ||
isArray = Array.isArray(current); | ||
@@ -125,3 +145,8 @@ if (Array.isArray(part)) { | ||
// Ex. update('data', { from: 3, to: 12, by: 2 }, 'label', l => l + ' !!!'); | ||
const {from = 0, to = current.length - 1, by = 1} = part; | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -137,2 +162,3 @@ updatePath(current, [i].concat(path), traversed.concat([i])); | ||
let value = path[0]; | ||
if (typeof value === 'function') { | ||
@@ -142,2 +168,3 @@ const currentPart = current[part]; | ||
} | ||
if (isWrappable(current[part]) && isWrappable(value) && !Array.isArray(value)) { | ||
@@ -149,4 +176,4 @@ mergeState(current[part], value); | ||
function createState(state = {}) { | ||
state = unwrap(state); | ||
function createState(state) { | ||
state = unwrap(state || {}); | ||
const wrappedState = wrap(state); | ||
@@ -171,4 +198,5 @@ | ||
if (target === previous) return; | ||
if (!isWrappable(target) || (previous == null)) { | ||
(target !== previous) && setProperty(parent, property, target); | ||
if (!isWrappable(target) || previous == null) { | ||
target !== previous && setProperty(parent, property, target); | ||
return; | ||
@@ -178,15 +206,25 @@ } | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || (key && target[0][key] != null))) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal, | ||
temp = new Array(target.length), | ||
newIndices = new Map(); | ||
// skip common prefix and suffix | ||
if (target.length && previous.length && (!merge || key && target[0][key] != null)) { | ||
let i, | ||
j, | ||
start, | ||
end, | ||
newEnd, | ||
item, | ||
newIndicesNext, | ||
keyVal, | ||
temp = new Array(target.length), | ||
newIndices = new Map(); // skip common prefix and suffix | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start][key] === target[start][key]); start++) { | ||
applyState(target[start], previous, start, merge, key); | ||
} | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= 0 && newEnd >= 0 && (previous[end] === target[newEnd] || key && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
temp[newEnd] = previous[end]; | ||
} | ||
// prepare a map of all indices in target | ||
} // prepare a map of all indices in target | ||
newIndicesNext = new Array(newEnd + 1); | ||
for (j = newEnd; j >= start; j--) { | ||
@@ -198,4 +236,5 @@ item = target[j]; | ||
newIndices.set(keyVal, j); | ||
} | ||
// step through all old items to check reuse | ||
} // step through all old items to check reuse | ||
for (i = start; i <= end; i++) { | ||
@@ -205,2 +244,3 @@ item = previous[i]; | ||
j = newIndices.get(keyVal); | ||
if (j !== undefined && j !== -1) { | ||
@@ -211,4 +251,5 @@ temp[j] = previous[i]; | ||
} | ||
} | ||
// set all the new values | ||
} // set all the new values | ||
for (j = start; j < target.length; j++) { | ||
@@ -218,4 +259,3 @@ if (temp.hasOwnProperty(j)) { | ||
applyState(target[j], previous, j, merge, key); | ||
} | ||
else setProperty(previous, j, target[j]); | ||
} else setProperty(previous, j, target[j]); | ||
} | ||
@@ -227,2 +267,3 @@ } else { | ||
} | ||
if (previous.length > target.length) setProperty(previous, 'length', target.length); | ||
@@ -233,14 +274,18 @@ return; | ||
const targetKeys = Object.keys(target); | ||
for (let i = 0, len = targetKeys.length; i < len; i++) { | ||
applyState(target[targetKeys[i]], previous, targetKeys[i], merge, key); | ||
} | ||
const previousKeys = Object.keys(previous); | ||
for (let i = 0, len = previousKeys.length; i < len; i++) { | ||
if (target[previousKeys[i]] === undefined) setProperty(previous, previousKeys[i], undefined); | ||
} | ||
} | ||
} // Diff method for setState | ||
// Diff method for setState | ||
function reconcile(path, options = {}) { | ||
let value; | ||
if (Array.isArray(path)) { | ||
@@ -252,13 +297,20 @@ value = path.pop(); | ||
} else { | ||
path = Array.prototype.slice.call(arguments, 0, -1), | ||
value = arguments[arguments.length - 1]; | ||
path = Array.prototype.slice.call(arguments, 0, -1), value = arguments[arguments.length - 1]; | ||
options = {}; | ||
} | ||
const { merge, key = 'id' } = options; | ||
const { | ||
merge, | ||
key = 'id' | ||
} = options; | ||
return state => { | ||
state = unwrap(state); | ||
if (path) { | ||
for (let i = 0; i < path.length - 1; i += 1) state = state[path[i]]; | ||
applyState(value, state, path[path.length - 1], merge, key); | ||
} else applyState(value, { state }, 'state', merge, key); | ||
} else applyState(value, { | ||
state | ||
}, 'state', merge, key); | ||
}; | ||
@@ -270,10 +322,14 @@ } | ||
let setter; | ||
if (comparator) { | ||
let age = -1; | ||
setter = v => { | ||
if (!comparator(value, v)) { | ||
const time = d.clock().time(); | ||
if (time === age) { | ||
throw new Error(`Conflicting value update: ${v} is not the same as ${value}`); | ||
} | ||
age = time; | ||
@@ -285,7 +341,8 @@ value = v; | ||
} else setter = d.next.bind(d); | ||
return [d.current.bind(d), setter]; | ||
} | ||
function createMemo(fn, seed) { return S(fn, seed); } | ||
function createMemo(fn, seed) { | ||
return S(fn, seed); | ||
} | ||
function createEffect(fn, deps, defer) { | ||
@@ -295,3 +352,8 @@ deps ? S.on(deps, fn, undefined, defer) : S.makeComputationNode(fn); | ||
const { root: createRoot, cleanup: onCleanup, sample, freeze } = S; | ||
const { | ||
root: createRoot, | ||
cleanup: onCleanup, | ||
sample, | ||
freeze | ||
} = S; | ||
@@ -298,0 +360,0 @@ exports.createEffect = createEffect; |
{ | ||
"name": "solid-js", | ||
"description": "A declarative JavaScript library for building user interfaces.", | ||
"version": "0.5.0", | ||
"version": "0.5.1-beta.1", | ||
"author": "Ryan Carniato", | ||
@@ -13,5 +13,9 @@ "license": "MIT", | ||
"module": "dist/solid.js", | ||
"types": "types/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"prebuild": "rimraf dist/* lib/* types/*", | ||
"build": "run-p -cnl build:*", | ||
"build:js": "rollup -c", | ||
"build:types": "tsc", | ||
"prepublishOnly": "npm run build", | ||
@@ -21,11 +25,19 @@ "test": "npm run build && jest --coverage" | ||
"dependencies": { | ||
"dom-expressions": "~0.7.1", | ||
"dom-expressions": "~0.7.7", | ||
"s-js": "~0.4.9" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"coveralls": "^3.0.3", | ||
"jest": "~24.7.1", | ||
"npm-run-all": "^4.1.5", | ||
"hyper-dom-expressions": "0.7.3", | ||
"lit-dom-expressions": "0.7.3", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.10.0", | ||
"rollup-plugin-node-resolve": "^4.1.0" | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-node-resolve": "^4.1.0", | ||
"typescript": "^3.4.4" | ||
} | ||
} |
@@ -52,2 +52,8 @@ ## <img src="assets/logo.png" alt="drawing" width="500"/><br> The Deceptively Simple User Interface Library | ||
For example get started with Tagged Template Literal version in the browser by simply including a script tag on the page. | ||
```html | ||
<script src="https://unpkg.com/solid-standalone/html.min.js"></script> | ||
``` | ||
## Solid State | ||
@@ -121,2 +127,4 @@ | ||
> Prettier and some compile to JS libraries like CoffeeScript will strip Parenthesis causing issues with Solid's JSX. So unfortunately they are incompatible at this time. | ||
To get setup add this babel plugin config to your .babelrc, webpack, or rollup config: | ||
@@ -243,4 +251,4 @@ | ||
* [Redux Undoable Todos](https://codepen.io/ryansolid/pen/Rvrgro?editors=1000) on CodePen | ||
* [Simple Todos Template Literals](https://codepen.io/ryansolid/pen/GzQNWB?editors=0010) on CodePen | ||
* [Simple Todos HyperScript](https://codepen.io/ryansolid/pen/WPGobB?editors=0010) on CodePen | ||
* [Simple Todos Template Literals](https://codepen.io/ryansolid/pen/GzQNWB?editors=0010) on CodePen | ||
* [TodoMVC](https://github.com/ryansolid/solid-todomvc) Classic TodoMVC example | ||
@@ -259,4 +267,8 @@ * [WebComponent Todos](https://github.com/shprink/web-components-todo/tree/master/solid) Showing off Solid with Web Components | ||
Babel plugin that converts JSX to DOM Expressions. | ||
* [Lit DOM Expressions](https://github.com/ryansolid/lit-dom-expressions) | ||
Tagged Template Literal API for DOM Expressions. | ||
* [Hyper DOM Expressions](https://github.com/ryansolid/hyper-dom-expressions) | ||
HyperScript API for DOM Expressions. | ||
* [Solid Components](https://github.com/ryansolid/solid-components) | ||
Extensions to Solid.js that add a Web Component wrapper and a Context API. | ||
Extensions to Solid.js that add a Web Component wrapper with a Context API, and Hot Module Replacement. | ||
* [React Solid State](https://github.com/ryansolid/react-solid-state) | ||
@@ -268,2 +280,3 @@ React Hooks API to use Solid.js paradigm in your existing React apps. | ||
* [Building a Simple JavaScript App with Solid](https://levelup.gitconnected.com/building-a-simple-javascript-app-with-solid-ff17c8836409) Dissecting building TodoMVC with Solid. | ||
* [Solid — The Best JavaScript UI Library You’ve Never Heard Of](https://levelup.gitconnected.com/solid-the-best-javascript-ui-library-youve-never-heard-of-297b22848ac1?source=friends_link&sk=d61fc9352b4a98c6c9f5f6bd2077a722) | ||
@@ -281,2 +294,2 @@ * [What Every JavaScript Framework Could Learn from React](https://medium.com/@ryansolid/what-every-javascript-framework-could-learn-from-react-1e2bbd9feb09?source=friends_link&sk=75b3f6f90eecc7d210814baa2d5ab52c) The lessons Solid learned from React. | ||
This project is still a work in progress. While Solid's change management is reaching stability (this repo), I am still refining the rendering API from the [Babel Plugin](https://github.com/ryansolid/babel-plugin-jsx-dom-expressions). | ||
This project is still a work in progress. While Solid's change management is reaching stability (this repo), I am still refining the rendering APIs from the [DOM Expressions](https://github.com/ryansolid/dom-expressions). |
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
45780
22
744
290
12
Updateddom-expressions@~0.7.7