Aleksei
banner
al3xnag.com
Aleksei
@al3xnag.com
a web software engineer or so
Tried many, including Obsidian and Notion.
Finally found Reflect, which is perfect for me. But it's paid.
December 15, 2024 at 7:33 PM
But I've learned. React Compiler deoptimizes first (unwraps useMemo useCallback) and then optimizes on its own, but more precisely.

The code becomes
console.log('heavy fn');
x = a + 1;
b = memoizedHeavyFn(x);

so I get console log on each rerender, but heavyFn isn't called until x is changed
November 30, 2024 at 11:11 PM
Weirdly, calling bind() on a function makes it "native".

While bind doesn't change the function body, it technically creates a new function, yet still preserves the name property... kinda... by adding a "bound" prefix. #javascript
November 20, 2024 at 11:38 AM
structuredClone facts (5/6)

Functions aren't cloneable, but you can manually clone them using fn.toString() & new Function() #javascript

No guarantees cloned fn will work, as it may depend on closures or globals. Native functions can't be cloned this way, as toString returns "{ [native code] }"
November 20, 2024 at 11:37 AM
structuredClone facts (4/6)

`window.postMessage` uses the structuredClone algorithm to transfer data, and IndexedDB uses it to store data #javascript
November 20, 2024 at 11:34 AM
structuredClone facts (3/6)

It doesn't preserve prototype chain for non-builtin object types. #javascript

A Map remains a Map, but MyClass becomes a plain JavaScript object. Null prototype is not preserved too (Object.create(null)).
November 20, 2024 at 11:33 AM
Be aware of XSS, custom elements, <base href>, and CSS when appending to a document. AFAIK DOMParser.parseFromString itself doesn't cause XSS until the DOM is attached to the live document."
November 20, 2024 at 11:22 AM
structuredClone facts (6/6)

While DOM nodes aren't cloneable by structuredClone, you can postMessage them between documents by using el.outerHTML to serialize and DOMParser.parseFromString to deserialize
(I have no idea why you'd want to do that) #javascript
November 20, 2024 at 11:19 AM
StructuredClone Facts (2/6)

Unlike JSON.stringify & parse:
- It raises exception if any deep prop is non-cloneable (e.g., function or dom node)
- It doesn't offer useful replacer/reviver callbacks

To safely handle arbitrary data, you have to manually traverse it first.
November 20, 2024 at 10:45 AM