Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper functions as external dependency module #184

Open
nippur72 opened this issue Aug 19, 2016 · 0 comments
Open

helper functions as external dependency module #184

nippur72 opened this issue Aug 19, 2016 · 0 comments

Comments

@nippur72
Copy link
Contributor

currently react-templates relies on lodash for doing some core functions (looping etc..) but such "helper" functions could be loaded as external dependency module instead of being "embedded" in the render function.

If so, it would be possible to fine tune and possibly avoid the direct dependency from lodash.

In PR #176 I've isolated the 4 "helper functions" actually used by react-templates:

__rtmap(collection, function);  // loops over a collection
__rtclass(object);              // turns a map object into a HTML class-attribute
__rtassign(dest,...objs)        // assign properties to destination object
__rtmergeprops(dest,...objs)    // as above, but considering "style" and "className"

They can be "enabled" with the new CLI option --external-helpers modulename.

I've also written a plain vanilla helper-functions module called react-templates-helpers that falls back on lodash.

As a bonus, since the helper functions are loaded separately one by one, in future it will be possible to take advantage of ES6 tree shaking features (rollupjs, webpack etc...).

Another small advantage is that now lodash is loaded only when needed, that is, if the component is small enough and doesn't use any of the helpers, lodash is left out because not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant