Skip to content

helper functions as external dependency module #184

@nippur72

Description

@nippur72

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions