diff --git a/packages/core/src/__tests__/helpers/index.ts b/packages/core/src/__tests__/helpers/index.ts index d6842192..72c446aa 100644 --- a/packages/core/src/__tests__/helpers/index.ts +++ b/packages/core/src/__tests__/helpers/index.ts @@ -1,11 +1,10 @@ import { ReactElement } from 'react'; import { TestingAdaptor, TestingAdaptorInstance } from './adaptor'; -import { ElementNode } from '../../reconciler/instance'; export class RenderResult { public constructor(private adaptorInstance: TestingAdaptorInstance) {} - public getContainer = (): ElementNode => this.adaptorInstance.data; + public getContainer = () => this.adaptorInstance.data; // ByText @@ -21,7 +20,8 @@ export class RenderResult { // TODO: }; - public resolveUpdateCallback = (renderId?: string) => this.adaptorInstance.resolveUpdateCallback(renderId); + public resolveUpdateCallback = (renderId?: string) => + this.adaptorInstance.resolveUpdateCallback(renderId); public setManuallyResolvedUpdateCallback = (enabled: boolean) => { this.adaptorInstance.setManuallyResolvedUpdateCallback(enabled); diff --git a/packages/core/src/__tests__/updates.test.tsx b/packages/core/src/__tests__/updates.test.tsx index 721b4368..c0fc50d1 100644 --- a/packages/core/src/__tests__/updates.test.tsx +++ b/packages/core/src/__tests__/updates.test.tsx @@ -35,7 +35,7 @@ describe('updates', () => { adaptor.run(); updater(3); - expect(diff).toEqual({ 'c[0].c[0].text': '3' }); + expect(diff).toEqual({ 'meta.children[0].children[0].text': '3' }); }); it('create or remove instance, re-render the whole sub-tree', () => { @@ -55,13 +55,13 @@ describe('updates', () => { adaptor.run(); updater(true); - expect(Object.keys(diff)).toEqual(['c[0].c[1]']); - expect(diff['c[0].c[1]'].c.length).toEqual(1); + expect(Object.keys(diff)).toEqual(['meta.children[0].children[1]']); + expect(diff['meta.children[0].children[1]'].children.length).toEqual(1); updater(false); - expect(Object.keys(diff)).toEqual(['c[0].c[1]']); - expect(diff['c[0].c[1]'].c.length).toEqual(0); + expect(Object.keys(diff)).toEqual(['meta.children[0].children[1]']); + expect(diff['meta.children[0].children[1]'].children.length).toEqual(0); }); it('only update events, should not trigger setData', () => { @@ -102,6 +102,6 @@ describe('updates', () => { // @ts-expect-error updater(false); - expect(Object.keys(diff)).toEqual(['c[0].sid']); + expect(Object.keys(diff)).toEqual(['meta.children[0].simplifiedId']); }); }); diff --git a/packages/core/src/adaptor/__tests__/__snapshots__/wechat.test.tsx.snap b/packages/core/src/adaptor/__tests__/__snapshots__/wechat.test.tsx.snap index 341e5e6d..8a70ae50 100644 --- a/packages/core/src/adaptor/__tests__/__snapshots__/wechat.test.tsx.snap +++ b/packages/core/src/adaptor/__tests__/__snapshots__/wechat.test.tsx.snap @@ -2,17 +2,19 @@ exports[`WeChatAdaptor works with Page 1`] = ` Object { - "c": Array [ - Object { - "c": Array [], - "id": 2, - "props": Object {}, - "sid": 0, - "type": "view", - }, - ], - "id": 1, - "props": Object {}, - "type": "GOJI_VIRTUAL_ROOT", + "meta": Object { + "children": Array [ + Object { + "children": Array [], + "gojiId": 2, + "props": Object {}, + "simplifiedId": 0, + "type": "view", + }, + ], + "gojiId": 1, + "props": Object {}, + "type": "GOJI_VIRTUAL_ROOT", + }, } `; diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 0f489535..e628ee8e 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -19,3 +19,36 @@ export const SIMPLIFY_COMPONENTS: Array = [ events: [], }, ]; + +/** + * Get identifiers used by template. For production we use shorter identifiers for less bundle size. + * This function is shared by both `@goji/core` and `@goji/webpack-plugin`. + * + * meta: for element data source, e.g. `