ylem
ylem copied to clipboard
ObserveArray.map() tries to convert JSX into proxies
When the map()
function is called on a ObserveArray
it tries to convert all the items in it into Proxies. This is not necessary when the map is returning JSX.
ex:
{todos.map(todo => (
<div>{todo.name}</div>
))}
Having to convert the JSX into proxies wastes time and isn't necessary.
A solution was discussed whereby from ylem we override the can-observe
function which tells map()
to do this. We can first check if the contents are JSX, if so we don't convert them to proxies, otherwise we just pass it off to the original can-observe
function.
Something like this:
const makeObserve = require('can-observe/src/-make-observe');
const React = require('react');
const observe = makeObserve.observe;
makeObserve.observe = function(input) {
if (React.isValidElement(input)) {
return input;
}
return observe(input);
};