Comparing version 1.5.6 to 1.5.7
# Changelog | ||
## 1.5.7- 2021-01-06 | ||
- Performance and Memory improvements | ||
## 1.5.6- 2021-01-05 | ||
@@ -4,0 +8,0 @@ |
@@ -941,6 +941,6 @@ // Safari Polyfills | ||
// Core of the library | ||
function generateProxy(obj = {}) { | ||
function generateProxy(obj) { | ||
const handlers = Symbol("handlers"); // For observer pattern | ||
const boundFunctions = new WeakMap(); | ||
const proxy = new Proxy(obj, { | ||
const proxy = new Proxy(obj ?? {}, { | ||
// If receiver is a getter, then it is the object on which the search first started for the property|key -> Proxy | ||
@@ -1106,3 +1106,3 @@ set(target, key, val, receiver) { | ||
// If oldVal is a Proxy - clean it | ||
!reuseElements && cleanProxy(oldVal); | ||
!reuseElements && oldVal && cleanProxy(oldVal); | ||
return returnSet; | ||
@@ -1182,8 +1182,5 @@ }, | ||
}); | ||
if (!Reflect.has(proxy, _boundFunctions)) | ||
queueMicrotask(() => { | ||
if (proxy === hydro) | ||
Reflect.defineProperty(proxy, _boundFunctions, { | ||
value: boundFunctions, | ||
}); | ||
if (!obj) | ||
Reflect.defineProperty(proxy, _boundFunctions, { | ||
value: boundFunctions, | ||
}); | ||
@@ -1341,2 +1338,3 @@ return proxy; | ||
setReactivity(rootElem); | ||
onCleanup(unset, rootElem, data); | ||
viewElements = false; | ||
@@ -1350,2 +1348,3 @@ observe(data, (newData, oldData) => { | ||
rootElem.textContent = ""; | ||
schedule(() => oldData.forEach((data) => (data = null))); | ||
} | ||
@@ -1360,3 +1359,5 @@ else if (reuseElements) { | ||
// Add to existing | ||
if (oldData?.length && newData?.length > oldData?.length) { | ||
if (oldData?.length && | ||
newData?.length > oldData?.length && | ||
newData[0] === oldData[0]) { | ||
const length = oldData.length; | ||
@@ -1371,2 +1372,6 @@ const slicedData = newData.slice(length); | ||
else if (oldData?.length === 0 || (!reuseElements && newData?.length)) { | ||
if (!reuseElements && oldData?.length && rootElem.hasChildNodes()) { | ||
rootElem.textContent = ""; | ||
schedule(() => oldData.forEach((data) => (data = null))); | ||
} | ||
const elements = newData.map(renderFunction); | ||
@@ -1373,0 +1378,0 @@ rootElem.append(...elements); |
{ | ||
"name": "hydro-js", | ||
"version": "1.5.6", | ||
"version": "1.5.7", | ||
"description": "A lightweight reactive library", | ||
@@ -32,3 +32,3 @@ "type": "module", | ||
"@types/concurrently": "^6.4.0", | ||
"@web/test-runner": "^0.13.24", | ||
"@web/test-runner": "^0.13.25", | ||
"@web/test-runner-playwright": "^0.8.8", | ||
@@ -35,0 +35,0 @@ "concurrently": "^7.0.0", |
@@ -1237,7 +1237,7 @@ declare global { | ||
// Core of the library | ||
function generateProxy(obj = {}): hydroObject { | ||
function generateProxy(obj?: Record<PropertyKey, unknown>): hydroObject { | ||
const handlers = Symbol("handlers"); // For observer pattern | ||
const boundFunctions = new WeakMap<Function, Function>(); | ||
const proxy = new Proxy(obj, { | ||
const proxy = new Proxy(obj ?? {}, { | ||
// If receiver is a getter, then it is the object on which the search first started for the property|key -> Proxy | ||
@@ -1416,3 +1416,3 @@ set(target, key, val, receiver) { | ||
// If oldVal is a Proxy - clean it | ||
!reuseElements && cleanProxy(oldVal); | ||
!reuseElements && oldVal && cleanProxy(oldVal); | ||
@@ -1494,8 +1494,5 @@ return returnSet; | ||
}); | ||
if (!Reflect.has(proxy, _boundFunctions)) | ||
queueMicrotask(() => { | ||
if (proxy === hydro) | ||
Reflect.defineProperty(proxy, _boundFunctions, { | ||
value: boundFunctions, | ||
}); | ||
if (!obj) | ||
Reflect.defineProperty(proxy, _boundFunctions, { | ||
value: boundFunctions, | ||
}); | ||
@@ -1669,2 +1666,3 @@ | ||
if (rootElem.hasChildNodes()) setReactivity(rootElem); | ||
onCleanup(unset, rootElem, data); | ||
@@ -1682,2 +1680,3 @@ viewElements = false; | ||
rootElem.textContent = ""; | ||
schedule(() => oldData.forEach((data) => (data = null))); | ||
} else if (reuseElements) { | ||
@@ -1692,3 +1691,7 @@ for (let i = 0; i < oldData?.length && newData?.length; i++) { | ||
// Add to existing | ||
if (oldData?.length && newData?.length > oldData?.length) { | ||
if ( | ||
oldData?.length && | ||
newData?.length > oldData?.length && | ||
newData[0] === oldData[0] | ||
) { | ||
const length = oldData.length; | ||
@@ -1705,2 +1708,7 @@ const slicedData = newData.slice(length); | ||
else if (oldData?.length === 0 || (!reuseElements && newData?.length)) { | ||
if (!reuseElements && oldData?.length && rootElem.hasChildNodes()) { | ||
rootElem.textContent = ""; | ||
schedule(() => oldData.forEach((data) => (data = null))); | ||
} | ||
const elements = newData.map(renderFunction); | ||
@@ -1707,0 +1715,0 @@ rootElem.append(...elements); |
282915
5170