This PR refactored the data structure in template and setData JSON data.
GojiJS now provides 2 versions of data structure according to current build environment (yarn start or yarn build), one of them is for development with full fields name, another is for production with shorten name. E.g. meta.props.className => m.p.className could save more bundle size.
Development:
Production (formatted):
All fleids of an element data, including type/props/children and etc., are all stored in a standalone object named meta. E.g. class="{{props.className}}" => class="{{meta.props.className}}".
Why
More clear field names bring better code maintainable. The bundle size won't increase or even decrease because shorter name.
I created a new function getTemplateIds that returns needed identifiers used by templates. This function can be accessed via import { unstable_getTemplateIds as getTemplateIds } from '@goji/core'; so every GojiJS packages could share it.
const ids = getTemplateIds();
console.log(ids.type); // logs `type` on development env and `t` on production env
Finally I tested this PR on internal large project and checked everything went well.
What
This PR refactored the data structure in template and
setData
JSON data.yarn start
oryarn build
), one of them is for development with full fields name, another is for production with shorten name. E.g.meta.props.className
=>m.p.className
could save more bundle size.Development:
Production (formatted):
type
/props
/children
and etc., are all stored in a standalone object namedmeta
. E.g.class="{{props.className}}"
=>class="{{meta.props.className}}"
.Why
mate
object could avoid some unexpected issue ( https://github.com/airbnb/goji-js/issues/179 ).How
Both
@goji/core
and@goji/cli
should be modified.I created a new function
getTemplateIds
that returns needed identifiers used by templates. This function can be accessed viaimport { unstable_getTemplateIds as getTemplateIds } from '@goji/core';
so every GojiJS packages could share it.Finally I tested this PR on internal large project and checked everything went well.