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

Refactored the data structure in template and setData JSON data. #180

Merged
merged 1 commit into from
Nov 24, 2022

Conversation

malash
Copy link
Collaborator

@malash malash commented Nov 24, 2022

What

This PR refactored the data structure in template and setData JSON data.

  1. 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:

image

Production (formatted):

image

  1. 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

  1. More clear field names bring better code maintainable. The bundle size won't increase or even decrease because shorter name.
  2. The mate object could avoid some unexpected issue ( Value changes toundefined doesn't work on Baidu template #179 ).
  3. It enables the possiablility to fix some tricky bugs in the next step like Cannot use <include> in <template> on Alipay #140 Doesn't support <Picker> in Alipay #80 Does't support MovableArea + MovableView in Baidu. #79

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 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.

@malash malash force-pushed the refactor-template branch 4 times, most recently from d1e13db to c44262e Compare November 24, 2022 07:52
@malash malash marked this pull request as ready for review November 24, 2022 07:57
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

Successfully merging this pull request may close these issues.

3 participants