Comparing version 1.2.4 to 1.2.5
# Changelog | ||
## 1.2.5- 2020-12-22 | ||
- feat: diplay empty string instead of undefined for undefined reactive values | ||
- Bump deps | ||
## 1.2.4- 2020-12-17 | ||
@@ -4,0 +9,0 @@ |
@@ -182,2 +182,19 @@ // Safari Polyfills | ||
DOM.querySelectorAll("template[id^=lbInsertNodes]").forEach((template) => replaceElement(insertNodes.shift(), template, false)); | ||
setReactivity(DOM, eventFunctions); | ||
// Set reactive Behavior if only a Text Node is present | ||
if (DOM.childElementCount === 0 && DOM.firstChild) { | ||
setReactivitySingle(DOM.firstChild); | ||
// Return Text Node | ||
return DOM.firstChild; | ||
} | ||
// Return DocumentFragment | ||
if (DOM.childNodes.length > 1) | ||
return DOM; | ||
// Return Text Node | ||
if (!DOM.firstChild) | ||
return document.createTextNode(""); | ||
// Return Element | ||
return DOM.firstChild; | ||
} | ||
function setReactivity(DOM, eventFunctions) { | ||
// Set events and reactive behaviour(checks for {{ key }} where key is on hydro) | ||
@@ -191,3 +208,3 @@ const root = document.createNodeIterator(DOM, window.NodeFilter.SHOW_ELEMENT); | ||
// Set functions | ||
if (key in eventFunctions) { | ||
if (eventFunctions && key in eventFunctions) { | ||
const event = eventFunctions[key]; | ||
@@ -216,3 +233,3 @@ const eventName = elem.getAttribute(key); | ||
else { | ||
setReactivity(elem, key); | ||
setReactivitySingle(elem, key); | ||
} | ||
@@ -226,3 +243,3 @@ }); | ||
if (isTextNode(childNode)) { | ||
setReactivity(childNode); | ||
setReactivitySingle(childNode); | ||
} | ||
@@ -232,18 +249,4 @@ childNode = childNode.nextSibling; | ||
} | ||
// Set reactive Behavior if only a Text Node is present | ||
if (DOM.childElementCount === 0 && DOM.firstChild) { | ||
setReactivity(DOM.firstChild); | ||
// Return Text Node | ||
return DOM.firstChild; | ||
} | ||
// Return DocumentFragment | ||
if (DOM.childNodes.length > 1) | ||
return DOM; | ||
// Return Text Node | ||
if (!DOM.firstChild) | ||
return document.createTextNode(""); | ||
// Return Element | ||
return DOM.firstChild; | ||
} | ||
function setReactivity(node, key) { | ||
function setReactivitySingle(node, key) { | ||
let attr_OR_text, match; | ||
@@ -285,5 +288,7 @@ if (isTextNode(node)) { | ||
? JSON.stringify(resolvedValue) | ||
: resolvedValue; | ||
: resolvedValue ?? ""; | ||
attr_OR_text = attr_OR_text.replace(hydroMatch, textContent); | ||
node.nodeValue = attr_OR_text; | ||
if (attr_OR_text != null) { | ||
node.nodeValue = attr_OR_text; | ||
} | ||
} | ||
@@ -686,4 +691,5 @@ else { | ||
const sameObject = resolvedValue === returnVal; | ||
const setValue = sameObject || returnVal === undefined ? resolvedValue : returnVal; | ||
Reflect.set(resolvedObj, lastProp, setValue); | ||
if (sameObject) | ||
return; | ||
Reflect.set(resolvedObj, lastProp, returnVal ?? resolvedValue); | ||
} | ||
@@ -925,3 +931,3 @@ else { | ||
Reflect.defineProperty(proxy, handlers, { | ||
//TODO should be WeakValue in future | ||
//TODO: should be WeakValue in future | ||
value: new Map(), | ||
@@ -1137,2 +1143,2 @@ }); | ||
}; | ||
module.exports = { render, html, hydro, setGlobalSchedule, setReuseElements, setInsertDiffing, reactive, unset, setAsyncUpdate, unobserve, observe, ternary, emit, internals, getValue, onRender, onCleanup, $, $$, }; | ||
module.exports = { render, html, hydro, setGlobalSchedule, setReuseElements, setInsertDiffing, reactive, unset, setAsyncUpdate, unobserve, observe, ternary, emit, internals, getValue, onRender, onCleanup, setReactivity, $, $$, }; |
@@ -283,5 +283,7 @@ // Safari Polyfills | ||
? JSON.stringify(resolvedValue) | ||
: resolvedValue; | ||
: resolvedValue ?? ""; | ||
attr_OR_text = attr_OR_text.replace(hydroMatch, textContent); | ||
node.nodeValue = attr_OR_text; | ||
if (attr_OR_text != null) { | ||
node.nodeValue = attr_OR_text; | ||
} | ||
} | ||
@@ -684,4 +686,5 @@ else { | ||
const sameObject = resolvedValue === returnVal; | ||
const setValue = sameObject || returnVal === undefined ? resolvedValue : returnVal; | ||
Reflect.set(resolvedObj, lastProp, setValue); | ||
if (sameObject) | ||
return; | ||
Reflect.set(resolvedObj, lastProp, returnVal ?? resolvedValue); | ||
} | ||
@@ -688,0 +691,0 @@ else { |
{ | ||
"name": "hydro-js", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "A lightweight reactive library", | ||
@@ -18,3 +18,2 @@ "type": "module", | ||
"test": "tsc && wtr test.html --node-resolve --coverage --playwright --browsers chromium firefox webkit", | ||
"test:watch": "concurrently \"tsc -w\" \"webpack ./dist/tests/index.js -o ./dist/tests --mode production -w\" \"nodemon ./dist/tests/runner.js\"", | ||
"update": "npx npm-check-updates -u && npx typesync && npm i && npm outdated" | ||
@@ -35,4 +34,4 @@ }, | ||
"@types/concurrently": "^5.2.1", | ||
"@web/test-runner": "^0.10.2", | ||
"@web/test-runner-playwright": "^0.6.6", | ||
"@web/test-runner": "^0.11.0", | ||
"@web/test-runner-playwright": "^0.7.0", | ||
"concurrently": "^5.3.0", | ||
@@ -39,0 +38,0 @@ "serve": "^11.3.2", |
@@ -410,6 +410,8 @@ declare const window: any; | ||
? JSON.stringify(resolvedValue) | ||
: resolvedValue; | ||
: resolvedValue ?? ""; | ||
attr_OR_text = attr_OR_text.replace(hydroMatch, textContent); | ||
node.nodeValue = attr_OR_text; | ||
if (attr_OR_text != null) { | ||
node.nodeValue = attr_OR_text; | ||
} | ||
} else { | ||
@@ -927,6 +929,5 @@ if (key === "bind") { | ||
const sameObject = resolvedValue === returnVal; | ||
const setValue = | ||
sameObject || returnVal === undefined ? resolvedValue : returnVal; | ||
if (sameObject) return; | ||
Reflect.set(resolvedObj, lastProp, setValue); | ||
Reflect.set(resolvedObj, lastProp, returnVal ?? resolvedValue); | ||
} else { | ||
@@ -933,0 +934,0 @@ Reflect.set(resolvedObj, lastProp, val); |
210
src/test.ts
@@ -59,3 +59,3 @@ import { | ||
describe("setReuseElements", () => { | ||
test("code coverage", () => { | ||
it("code coverage", () => { | ||
setReuseElements(true); | ||
@@ -67,3 +67,3 @@ return true; | ||
describe("setGlobalSchedule", () => { | ||
test("sets asnycUpdate on hydro objects", () => { | ||
it("sets asnycUpdate on hydro objects", () => { | ||
hydro.schedule = {}; | ||
@@ -84,3 +84,3 @@ let cond = hydro.schedule.asyncUpdate === false; | ||
describe("setAsyncUpdate", () => { | ||
test("sets asnycUpdate on reactive object", () => { | ||
it("sets asnycUpdate on reactive object", () => { | ||
const schedule = reactive({}); | ||
@@ -92,3 +92,3 @@ setAsyncUpdate(schedule, false); | ||
test("works chained", () => { | ||
it("works chained", () => { | ||
const abc = reactive({ a: { b: 4 } }); | ||
@@ -218,3 +218,3 @@ setAsyncUpdate(abc.a, false); | ||
].forEach((tag) => { | ||
test(`is able to create element ${tag}`, () => { | ||
it(`is able to create element ${tag}`, () => { | ||
const elem = html`<${tag} />` as Element; | ||
@@ -225,11 +225,11 @@ return elem.localName === tag; | ||
test("returns empty text node", () => { | ||
it("returns empty text node", () => { | ||
return document.createTextNode("").isEqualNode(html``); | ||
}); | ||
test("returns text node", () => { | ||
it("returns text node", () => { | ||
return document.createTextNode("hello").isEqualNode(html`hello`); | ||
}); | ||
test("returns document fragment", () => { | ||
it("returns document fragment", () => { | ||
const node = html`<div><p>hi</p></div> | ||
@@ -244,3 +244,3 @@ <div><span>ho</span></div>` as DocumentFragment; | ||
test("returns element", () => { | ||
it("returns element", () => { | ||
const elem = html`<p>hello</p>` as Element; | ||
@@ -250,3 +250,3 @@ return elem.localName === "p" && elem.textContent!.includes("hello"); | ||
test("variable input (node)", () => { | ||
it("variable input (node)", () => { | ||
const p = html`<p>hi</p>`; | ||
@@ -257,3 +257,3 @@ const elem = html`<div>${p}</div>`; | ||
test("variable input (primitive value)", () => { | ||
it("variable input (primitive value)", () => { | ||
const test = "test"; | ||
@@ -264,11 +264,19 @@ const elem = html`<div>${test}</div>`; | ||
test("variable input (hydro)", () => { | ||
const elem = html`<div>{{ test}}</div>`; | ||
it("variable input (hydro)", () => { | ||
hydro.testValue = "test"; | ||
const elem = html`<div>{{ testValue }}</div>`; | ||
setTimeout(() => { | ||
hydro.test = null; | ||
hydro.testValue = null; | ||
}); | ||
return elem.textContent!.includes(hydro.test); | ||
return elem.textContent!.includes(hydro.testValue); | ||
}); | ||
test("variable input (reactive)", () => { | ||
it("variable input (reactive) - does not include undefined", () => { | ||
const data = reactive({}); | ||
const elem = html`<div>${data.test}</div>`; | ||
setTimeout(unset, 0, data); | ||
return !elem.textContent!.includes(String(undefined)); | ||
}); | ||
it("variable input (reactive)", () => { | ||
const test = reactive("test"); | ||
@@ -280,3 +288,3 @@ const elem = html`<div>${test}</div>`; | ||
test("variable input (eventListener)", () => { | ||
it("variable input (eventListener)", () => { | ||
const onClick = (e: any) => (e.currentTarget.textContent = 1); | ||
@@ -289,3 +297,3 @@ const elem = html`<div onclick=${onClick}>0</div>`; | ||
test("variable input (array - normal)", () => { | ||
it("variable input (array - normal)", () => { | ||
const arr = [42, "test"]; | ||
@@ -298,3 +306,3 @@ const elem = html`<div>${arr}</div>`; | ||
test("variable input (function)", () => { | ||
it("variable input (function)", () => { | ||
const onClick = (e: any) => | ||
@@ -309,3 +317,3 @@ (e.currentTarget.textContent = | ||
test("variable input (eventListener as object)", () => { | ||
it("variable input (eventListener as object)", () => { | ||
const onClick = { | ||
@@ -327,3 +335,3 @@ event: (e: any) => | ||
test("variable input (array - node)", () => { | ||
it("variable input (array - node)", () => { | ||
const p = html`<p>test</p>`; | ||
@@ -339,3 +347,3 @@ const arr = [42, p]; | ||
test("variable input (object)", () => { | ||
it("variable input (object)", () => { | ||
const props = { | ||
@@ -358,3 +366,3 @@ id: "test", | ||
test("variable input (object - with eventListenerObject)", () => { | ||
it("variable input (object - with eventListenerObject)", () => { | ||
const props = { | ||
@@ -384,3 +392,3 @@ id: "test", | ||
test("resolves deep reactive", () => { | ||
it("resolves deep reactive", () => { | ||
const person = reactive({ | ||
@@ -421,3 +429,3 @@ firstname: "Fabian", | ||
test("nested reactive", () => { | ||
it("nested reactive", () => { | ||
const list = reactive([ | ||
@@ -450,3 +458,3 @@ { text: "Lorem", success: true }, | ||
test("removes {{..}}) from html attribute", () => { | ||
it("removes {{..}}) from html attribute", () => { | ||
const attr = reactive({ id: "test" }); | ||
@@ -464,3 +472,3 @@ const elem = html`<p ${attr}></p>` as Element; | ||
test("two-way attribute", () => { | ||
it("two-way attribute", () => { | ||
const text = reactive("text"); | ||
@@ -585,3 +593,3 @@ const checked = reactive(["John", "Mike"]); | ||
test("works with different events on one element", () => { | ||
it("works with different events on one element", () => { | ||
let a, b, c; | ||
@@ -603,3 +611,3 @@ const elem = html`<p | ||
test("stringifies object", () => { | ||
it("stringifies object", () => { | ||
hydro.x = { a: 3 }; | ||
@@ -611,3 +619,3 @@ const elem = html`<p>{{x}}</p>`; | ||
test("removes bind element", () => { | ||
it("removes bind element", () => { | ||
hydro.y = { a: 3 }; | ||
@@ -620,3 +628,3 @@ const elem = html`<p bind="{{y}}">asd</p>`; | ||
test("removes bind element with multiple elements", () => { | ||
it("removes bind element with multiple elements", () => { | ||
hydro.z = 4; | ||
@@ -631,3 +639,3 @@ const elem = html`<p bind="{{z}}">asd</p>`; | ||
test("super rare manipulation of DOM Element", () => { | ||
it("super rare manipulation of DOM Element", () => { | ||
hydro.abc = { id: "jja", href: "cool" }; | ||
@@ -646,3 +654,3 @@ const elem = html`<a id="{{abc.id}}" href="{{abc.href}}" | ||
describe("compare", () => { | ||
test("lifecycle hooks and text Nodes - false - length", () => { | ||
it("lifecycle hooks and text Nodes - false - length", () => { | ||
const renderFn1 = () => 2; | ||
@@ -662,3 +670,3 @@ const renderFn2 = () => 3; | ||
test("lifecycle hooks and text Nodes - false - string", () => { | ||
it("lifecycle hooks and text Nodes - false - string", () => { | ||
const renderFn1 = () => 2; | ||
@@ -680,3 +688,3 @@ const renderFn2 = () => 3; | ||
test("returns false if child has different lifecycle hooks - onlyTextChildren", () => { | ||
it("returns false if child has different lifecycle hooks - onlyTextChildren", () => { | ||
const subelem1 = html`hello`; | ||
@@ -693,3 +701,3 @@ onRender(() => 2, subelem1); | ||
test("returns false if child has different lifecycle hooks", () => { | ||
it("returns false if child has different lifecycle hooks", () => { | ||
const subelem1 = html`hello`; | ||
@@ -706,3 +714,3 @@ onRender(() => 2, subelem1); | ||
test("lifecycle hooks and text Nodes - true", () => { | ||
it("lifecycle hooks and text Nodes - true", () => { | ||
const renderFn1 = () => 2; | ||
@@ -724,3 +732,3 @@ const renderFn2 = () => 2; | ||
test("same functions return true", () => { | ||
it("same functions return true", () => { | ||
const fn1 = () => 2; | ||
@@ -733,3 +741,3 @@ const fn2 = () => 2; | ||
test("same lifecycle hooks return true", () => { | ||
it("same lifecycle hooks return true", () => { | ||
const fn1 = () => 2; | ||
@@ -749,3 +757,3 @@ const fn2 = () => 2; | ||
test("different function return false", () => { | ||
it("different function return false", () => { | ||
const fn1 = () => 2; | ||
@@ -758,3 +766,3 @@ const fn2 = () => 3; | ||
test("different lifecycle hooks return false", () => { | ||
it("different lifecycle hooks return false", () => { | ||
const fn1 = () => 2; | ||
@@ -776,3 +784,3 @@ const fn2 = () => 3; | ||
describe("render", () => { | ||
test("does diffing with documentFragment", () => { | ||
it("does diffing with documentFragment", () => { | ||
setInsertDiffing(true); | ||
@@ -795,3 +803,3 @@ const elem1 = html`it`; | ||
test("do not reuseElements", () => { | ||
it("do not reuseElements", () => { | ||
setReuseElements(false); | ||
@@ -808,3 +816,3 @@ const elem1 = html`a`; | ||
test("async behavior", async () => { | ||
it("async behavior", async () => { | ||
// Code Coverage | ||
@@ -837,3 +845,3 @@ setGlobalSchedule(true); | ||
test("can render elements wrapped in reactive", async () => { | ||
it("can render elements wrapped in reactive", async () => { | ||
const number = reactive(5); | ||
@@ -860,3 +868,3 @@ const elem = reactive(html`<p>${number}</p>`); | ||
test("where does not exist - no render", () => { | ||
it("where does not exist - no render", () => { | ||
const elemCount = document.body.querySelectorAll("*").length; | ||
@@ -869,3 +877,3 @@ const unmount = render(html`<p>what</p>`, "#doesNotExist"); | ||
test("elem is DocumentFragment, no where", () => { | ||
it("elem is DocumentFragment, no where", () => { | ||
const elem = html`<div id="first">1</div> | ||
@@ -882,3 +890,3 @@ <div id="second">2</div>`; | ||
test("elem is svg, no where", () => { | ||
it("elem is svg, no where", () => { | ||
const elem = html`<svg height="100" width="100"> | ||
@@ -900,3 +908,3 @@ <circle | ||
test("elem is textNode, no where", () => { | ||
it("elem is textNode, no where", () => { | ||
const elem = html`what`; | ||
@@ -909,3 +917,3 @@ const unmount = render(elem); | ||
test("elem is Element, no where", () => { | ||
it("elem is Element, no where", () => { | ||
const elem = html`<p id="whatWhere">what</p>`; | ||
@@ -920,3 +928,3 @@ const unmount = render(elem); | ||
test("elem is DocumentFragment, with where", () => { | ||
it("elem is DocumentFragment, with where", () => { | ||
document.body.insertAdjacentHTML("beforeend", '<p id="hello">here</p>'); | ||
@@ -935,3 +943,3 @@ const elem = html`<div id="firstOne">1</div> | ||
test("elem is svg, with where", () => { | ||
it("elem is svg, with where", () => { | ||
document.body.insertAdjacentHTML( | ||
@@ -957,3 +965,3 @@ "beforeend", | ||
test("elem is textNode, with where", () => { | ||
it("elem is textNode, with where", () => { | ||
document.body.insertAdjacentHTML( | ||
@@ -974,3 +982,3 @@ "beforeend", | ||
test("elem is Element, with where", () => { | ||
it("elem is Element, with where", () => { | ||
document.body.insertAdjacentHTML( | ||
@@ -991,3 +999,3 @@ "beforeend", | ||
test("replace an element will replace the event", () => { | ||
it("replace an element will replace the event", () => { | ||
const click1 = (e: any) => (e.currentTarget.textContent = 1); | ||
@@ -1012,3 +1020,3 @@ const click2 = (e: any) => (e.currentTarget.textContent = 2); | ||
test("replacing elements will not stop their state", async () => { | ||
it("replacing elements will not stop their state", async () => { | ||
setInsertDiffing(true); | ||
@@ -1057,3 +1065,3 @@ const video1 = html` | ||
test("calls lifecyle hooks on deep elements", () => { | ||
it("calls lifecyle hooks on deep elements", () => { | ||
let subOnRender = false; | ||
@@ -1082,3 +1090,3 @@ let subOnCleanup = false; | ||
test("calls the correct lifecyle hooks when replacing elements", () => { | ||
it("calls the correct lifecyle hooks when replacing elements", () => { | ||
let subOnRender = false; | ||
@@ -1105,3 +1113,3 @@ let subOnCleanup = false; | ||
describe("reactive", () => { | ||
test("primitive value", () => { | ||
it("primitive value", () => { | ||
const counter = reactive(0); | ||
@@ -1129,3 +1137,3 @@ const unmount = render( | ||
test("reactive (object)", () => { | ||
it("reactive (object)", () => { | ||
let obj1 = reactive({ a: { b: 5 } }); | ||
@@ -1175,3 +1183,3 @@ let obj2 = reactive({ a: { b: 5 } }); | ||
test("reactive (array)", () => { | ||
it("reactive (array)", () => { | ||
const arr1 = reactive([1, [2]]); | ||
@@ -1249,3 +1257,3 @@ const arr2 = reactive([3, [4]]); | ||
describe("observe", () => { | ||
test("observe hydro", () => { | ||
it("observe hydro", () => { | ||
let test = 0; | ||
@@ -1267,3 +1275,3 @@ hydro.test = 0; | ||
test("observe reactive", () => { | ||
it("observe reactive", () => { | ||
let result = 0; | ||
@@ -1286,3 +1294,3 @@ const test = reactive(0); | ||
test("observe primitive - function", () => { | ||
it("observe primitive - function", () => { | ||
let result = 0; | ||
@@ -1304,3 +1312,3 @@ const test = reactive(0); | ||
test("observe not working for primitive with function and no return", () => { | ||
it("observe not working for primitive with function and no return", () => { | ||
let result = 0; | ||
@@ -1324,3 +1332,3 @@ const test = reactive(0); | ||
test("observe object", () => { | ||
it("observe object", () => { | ||
let result = 0; | ||
@@ -1341,3 +1349,3 @@ const test = reactive({ value: 0 }); | ||
}); | ||
test("observe object (return another) function", () => { | ||
it("observe object (return another) function", () => { | ||
let result = 0; | ||
@@ -1360,3 +1368,3 @@ const test = reactive({ value: 0 }); | ||
}); | ||
test("observe object (modified arg)", () => { | ||
it("observe object (modified arg)", () => { | ||
let result = 0; | ||
@@ -1381,3 +1389,3 @@ const test = reactive({ value: 0 }); | ||
test("observe object and modify arg plus no return", () => { | ||
it("observe object and modify arg plus no return", () => { | ||
let result = 0; | ||
@@ -1401,3 +1409,3 @@ const test = reactive({ value: 0 }); | ||
test("observe object and modify arg plus no return - new syntax", () => { | ||
it("observe object and modify arg plus no return - new syntax", () => { | ||
let result = 0; | ||
@@ -1421,3 +1429,3 @@ const test = reactive({ value: 0 }); | ||
describe("getValue", () => { | ||
test("primitive value", () => { | ||
it("primitive value", () => { | ||
const x = reactive(4); | ||
@@ -1428,3 +1436,3 @@ setTimeout(unset, 0, x); | ||
test("object", () => { | ||
it("object", () => { | ||
const obj = { test: 4 }; | ||
@@ -1436,3 +1444,3 @@ const x = reactive(obj); | ||
test("array", () => { | ||
it("array", () => { | ||
const arr = [4]; | ||
@@ -1446,3 +1454,3 @@ const x = reactive(arr); | ||
describe("unobserve", () => { | ||
test("works chained", () => { | ||
it("works chained", () => { | ||
const abc = reactive({ a: { b: 4 } }); | ||
@@ -1456,3 +1464,3 @@ unobserve(abc.a); | ||
describe("unset", () => { | ||
test("works chained", () => { | ||
it("works chained", () => { | ||
const abc = reactive({ a: { b: 4 } }); | ||
@@ -1466,3 +1474,3 @@ unset(abc.a); | ||
describe("ternary", () => { | ||
test("condition as function", () => { | ||
it("condition as function", () => { | ||
const isTrue = reactive(true); | ||
@@ -1486,3 +1494,3 @@ | ||
test("re-renders component", () => { | ||
it("re-renders component", () => { | ||
const isToggleOn = reactive(false); | ||
@@ -1512,3 +1520,3 @@ let unmount: Function; | ||
test("re-renders component - function", () => { | ||
it("re-renders component - function", () => { | ||
const isToggleOn = reactive(false); | ||
@@ -1544,3 +1552,3 @@ let unmount: Function; | ||
describe("onRender", () => { | ||
test("works with DocumentFragment", () => { | ||
it("works with DocumentFragment", () => { | ||
const elem = html`<p>1</p> | ||
@@ -1556,3 +1564,3 @@ <p>2</p>`; | ||
test("onRender", () => { | ||
it("onRender", () => { | ||
let count = 0; | ||
@@ -1578,3 +1586,3 @@ const x = reactive(4); | ||
describe("onCleanup", () => { | ||
test("onCleanup", () => { | ||
it("onCleanup", () => { | ||
let count = 0; | ||
@@ -1597,3 +1605,3 @@ const x = reactive(4); | ||
describe("generateProxy", () => { | ||
test("add observer to observers", () => { | ||
it("add observer to observers", () => { | ||
hydro.x = 7; | ||
@@ -1618,3 +1626,3 @@ let firstObserver = false; | ||
test("handles swapping data correctly", () => { | ||
it("handles swapping data correctly", () => { | ||
hydro.data = [{ name: "Sebastian" }, { name: "Peter" }]; | ||
@@ -1644,3 +1652,3 @@ | ||
test("handles rejecting promise as expected", async () => { | ||
it("handles rejecting promise as expected", async () => { | ||
hydro.prom = Promise.reject("This is a Test for a rejected Promise"); | ||
@@ -1651,3 +1659,3 @@ await sleep(1); | ||
test("intern properties", () => { | ||
it("intern properties", () => { | ||
hydro.obj = {}; | ||
@@ -1667,3 +1675,3 @@ | ||
test("will not set falsy boolean attributes", () => { | ||
it("will not set falsy boolean attributes", () => { | ||
const checked = reactive(0); | ||
@@ -1687,3 +1695,3 @@ const elem = html`<input checked=${checked} />` as Element; | ||
test("will not set falsy boolean attributes on obj", () => { | ||
it("will not set falsy boolean attributes on obj", () => { | ||
const checked = reactive({ disabled: "" }); | ||
@@ -1703,3 +1711,3 @@ const attr = reactive({ id: "boolAttr" }); | ||
test("updateDOM does not remove focus", () => { | ||
it("updateDOM does not remove focus", () => { | ||
const count = reactive(0); | ||
@@ -1731,3 +1739,3 @@ const increment = () => count(1); | ||
test("using reactive variables in one variable - variable will be updated too", () => { | ||
it("using reactive variables in one variable - variable will be updated too", () => { | ||
const dynamicOne = reactive("classA"); | ||
@@ -1773,3 +1781,3 @@ const dynamicTwo = reactive("classB"); | ||
test("swap operation (hydro)", () => { | ||
it("swap operation (hydro)", () => { | ||
hydro.array = ["x", "y"]; | ||
@@ -1785,3 +1793,3 @@ [hydro.array[0], hydro.array[1]] = [hydro.array[1], hydro.array[0]]; | ||
test("swap operation (reactive)", () => { | ||
it("swap operation (reactive)", () => { | ||
const array = reactive(["x", "y"]); | ||
@@ -1798,3 +1806,3 @@ | ||
test("promise handling", async () => { | ||
it("promise handling", async () => { | ||
const promise = reactive( | ||
@@ -1825,3 +1833,3 @@ new Promise((resolve) => setTimeout(() => resolve(777), 200)) | ||
describe("integration", () => { | ||
test("attributes are reactive", () => { | ||
it("attributes are reactive", () => { | ||
const id = "firstId"; | ||
@@ -1846,3 +1854,3 @@ const href = "https://www.google.com/"; | ||
test("event is reactive", () => { | ||
it("event is reactive", () => { | ||
const props = reactive({ | ||
@@ -1867,3 +1875,3 @@ onclick: (e: any) => (e.currentTarget.textContent = 1), | ||
test("event is reactive with eventobject", () => { | ||
it("event is reactive with eventobject", () => { | ||
const props = reactive({ | ||
@@ -1894,3 +1902,3 @@ onclick: (e: any) => (e.currentTarget.textContent = 1), | ||
test("eventObject is reactive", () => { | ||
it("eventObject is reactive", () => { | ||
const testEvent = reactive({ | ||
@@ -1934,3 +1942,3 @@ event: (e: any) => | ||
test("eventObject can be replaced by normal fn", () => { | ||
it("eventObject can be replaced by normal fn", () => { | ||
const testEvent2 = reactive({ | ||
@@ -1973,3 +1981,3 @@ event: (e: any) => | ||
describe("data handling check", () => { | ||
test("hydro is {}", async () => { | ||
it("hydro is {}", async () => { | ||
await sleep(700); | ||
@@ -1979,3 +1987,3 @@ return JSON.stringify(hydro) === JSON.stringify({}); | ||
test("hydro does not have any observers", async () => { | ||
it("hydro does not have any observers", async () => { | ||
await sleep(700); | ||
@@ -1985,3 +1993,3 @@ return hydro.getObservers().size === 0; | ||
test("body has DOM Elements - unmount", async () => { | ||
it("body has DOM Elements - unmount", async () => { | ||
await sleep(700); | ||
@@ -2033,3 +2041,3 @@ setTimeout(() => document.body.dispatchEvent(new CustomEvent("done"))); | ||
async function test(name: string, testFn: () => boolean | Promise<boolean>) { | ||
async function it(name: string, testFn: () => boolean | Promise<boolean>) { | ||
if (await testFn()) { | ||
@@ -2036,0 +2044,0 @@ results.push({ name, success: true }); |
Sorry, the diff of this file is not supported yet
272849
5344