3 ms·
Nice optimization for rerendering HTML, I wonder if React uses this technique. Also, sometimes I wonder if it's worth pulling out separate concepts from a data
by munro 12y ago
Nice optimization for rerendering HTML, I wonder if React uses this technique.
Also, sometimes I wonder if it's worth pulling out separate concepts from a data structure ... I usually just embed them, but I always consider building a parallel data structure.
data HTML = Text String | Element String [HTML]
data MemoizedHTML = MemoizedText String | MemoizedElement String [MemoizedHTML]
rendered :: (HTML, MemoizedHTML)
rendered = (
Element "foo" [
Element "bar" [],
Text "hello"
],
MemoizedElement "<foo><bar />hello</foo>" [
MemoizedElement "<bar />" [],
MemoizedText "hello"
]
)