bitovi / bitovi/ylem

ObserveArray.map() tries to convert JSX into proxies

Open
#183 0 comments 0 reactions 1 assignee Claimed by @mikedane View on GitHub
enhancement
Dominant language
JavaScript
Stars
42
Forks
4
PR merge metrics
No merged PRs in 30d

Description

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:
```js
{todos.map(todo => (

{todo.name}

))}
```

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:

```js
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);
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.