@gojijs/core
Advanced tools
Comparing version 0.1.7 to 0.2.0
import { GOJI_ROOT_VDOM } from './constants'; | ||
import { FiberRoot } from 'react-reconciler'; | ||
import { Instance, TextInstance } from './hostConfig'; | ||
import { LifecycleName } from './lifecycles'; | ||
export declare class Container { | ||
@@ -10,7 +11,8 @@ constructor(context: any); | ||
private applyUpdate; | ||
inQueue: boolean; | ||
private inQueue; | ||
requestUpdate(): void; | ||
registerEventHandler(handlerKey: string, handler: Function): void; | ||
unregisterEventHandler(handlerKey: string): void; | ||
getPublicRootInstance(): any; | ||
private getPublicRootInstance; | ||
emitLifecycle(eventName: LifecycleName, eventData?: any): void; | ||
} |
@@ -70,4 +70,10 @@ var _a; | ||
} | ||
emitLifecycle(eventName, eventData) { | ||
const publicRootInstance = this.getPublicRootInstance(); | ||
if (publicRootInstance) { | ||
publicRootInstance.emitLifecycle(eventName, eventData); | ||
} | ||
} | ||
} | ||
_a = GOJI_ROOT_VDOM; | ||
//# sourceMappingURL=container.js.map |
@@ -1,6 +0,5 @@ | ||
import React from 'react'; | ||
import { ReactNode } from 'react'; | ||
import { Container } from './container'; | ||
interface PageThisType { | ||
__container?: Container; | ||
wrapper: any; | ||
} | ||
@@ -21,3 +20,3 @@ export interface MiniProgramPageConfig { | ||
} | ||
export default function createPageConfig(Page: React.ComponentType<any>): MiniProgramPageConfig; | ||
export default function createPageConfig(element: ReactNode): MiniProgramPageConfig; | ||
export {}; |
import React from 'react'; | ||
import createPageWrapper from './createPageWrapper'; | ||
import { internalRender } from './render'; | ||
import { Container } from './container'; | ||
export default function createPageConfig(Page) { | ||
import { LifecycleWrapper } from './lifecycles/wrapper'; | ||
export default function createPageConfig(element) { | ||
return { | ||
onLoad(query) { | ||
const PageWrapper = createPageWrapper(Page, query); | ||
onLoad(options) { | ||
this.__container = new Container(this); | ||
internalRender(React.createElement(PageWrapper), this.__container); | ||
internalRender(React.createElement(LifecycleWrapper, null, element), this.__container); | ||
this.__container.emitLifecycle('onLoad', options); | ||
}, | ||
onUnload() { | ||
this.__container.emitLifecycle('onUnload'); | ||
if (this.__container) { | ||
@@ -19,30 +20,30 @@ internalRender(null, this.__container); | ||
onShow() { | ||
this.__container.getPublicRootInstance().onShow(); | ||
this.__container.emitLifecycle('onShow'); | ||
}, | ||
onHide() { | ||
this.__container.getPublicRootInstance().onHide(); | ||
this.__container.emitLifecycle('onHide'); | ||
}, | ||
onPullDownRefresh() { | ||
this.__container.getPublicRootInstance().onPullDownRefresh(); | ||
this.__container.emitLifecycle('onPullDownRefresh'); | ||
}, | ||
onReachBottom() { | ||
this.__container.getPublicRootInstance().onReachBottom(); | ||
this.__container.emitLifecycle('onReachBottom'); | ||
}, | ||
onPageScroll() { | ||
this.__container.getPublicRootInstance().onPageScroll(); | ||
this.__container.emitLifecycle('onPageScroll'); | ||
}, | ||
onShareAppMessage() { | ||
this.__container.getPublicRootInstance().onShareAppMessage(); | ||
this.__container.emitLifecycle('onShareAppMessage'); | ||
}, | ||
onTitleClick() { | ||
this.__container.getPublicRootInstance().onTitleClick(); | ||
this.__container.emitLifecycle('onTitleClick'); | ||
}, | ||
onOptionMenuClick() { | ||
this.__container.getPublicRootInstance().onOptionMenuClick(); | ||
this.__container.emitLifecycle('onOptionMenuClick'); | ||
}, | ||
onPopMenuClick() { | ||
this.__container.getPublicRootInstance().onPopMenuClick(); | ||
this.__container.emitLifecycle('onPopMenuClick'); | ||
}, | ||
onPullIntercept() { | ||
this.__container.getPublicRootInstance().onPullIntercept(); | ||
this.__container.emitLifecycle('onPullIntercept'); | ||
}, | ||
@@ -49,0 +50,0 @@ }; |
@@ -1,4 +0,5 @@ | ||
import React from 'react'; | ||
export declare const render: (App: React.ComponentType<any>) => any; | ||
/// <reference types="react" /> | ||
export declare const render: (element: JSX.Element) => any; | ||
export declare const unstable_setBridgeType: (newBridgeType: string) => void; | ||
export * from './factoryComponents'; | ||
export * from './lifecycles'; |
import createPageConfig from './createPageConfig'; | ||
// @ts-ignore | ||
export const render = (App) => Page(createPageConfig(App)); | ||
export const render = (element) => Page(createPageConfig(element)); | ||
let bridgeType = 'template'; | ||
@@ -10,2 +10,3 @@ // FIXME: will be removed later | ||
export * from './factoryComponents'; | ||
export * from './lifecycles'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@gojijs/core", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Goji Core", | ||
@@ -18,2 +18,9 @@ "main": "dist/index.js", | ||
"jest": { | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"./src/**/*.{js,jsx,ts,tsx}" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"<rootDir>/setupTests.js" | ||
], | ||
"transform": { | ||
@@ -26,4 +33,8 @@ "^.+\\.(j|t)sx?$": "./babel-jest.config.js" | ||
"@babel/preset-env": "^7.5.5", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@types/enzyme": "^3.10.3", | ||
"@types/jest": "^24.0.18", | ||
"@types/react": "^16.8.23", | ||
"@types/react-dom": "^16.9.0", | ||
"@types/react-reconciler": "^0.18.0", | ||
@@ -33,4 +44,7 @@ "@types/scheduler": "^0.12.1", | ||
"babel-jest": "^24.9.0", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.14.0", | ||
"jest": "^24.9.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.9.0", | ||
"rimraf": "^3.0.0", | ||
@@ -50,3 +64,3 @@ "typescript": "^3.5.3" | ||
}, | ||
"gitHead": "6e0646d55e53914ba9a588eb5ed05e6a8760c595" | ||
"gitHead": "e165b2080f29c1d0c9221c7e480495d89c39b00e" | ||
} |
@@ -5,2 +5,3 @@ import { GOJI_ROOT_VDOM } from './constants'; | ||
import { Instance, TextInstance } from './hostConfig'; | ||
import { LifecycleWrapper, LifecycleName } from './lifecycles'; | ||
@@ -60,5 +61,5 @@ const getGlobalVariable = () => { | ||
inQueue = false; | ||
private inQueue = false; | ||
requestUpdate() { | ||
public requestUpdate() { | ||
if (this.inQueue) { | ||
@@ -71,7 +72,7 @@ return; | ||
registerEventHandler(handlerKey: string, handler: Function) { | ||
public registerEventHandler(handlerKey: string, handler: Function) { | ||
this.__context[handlerKey] = handler; | ||
} | ||
unregisterEventHandler(handlerKey: string) { | ||
public unregisterEventHandler(handlerKey: string) { | ||
// FIXME: fix delete 性能问题 | ||
@@ -81,3 +82,3 @@ delete this.__context[handlerKey]; | ||
getPublicRootInstance() { | ||
private getPublicRootInstance() { | ||
const container = this.__rootContainer!; | ||
@@ -90,2 +91,9 @@ var containerFiber = container.current; | ||
} | ||
public emitLifecycle(eventName: LifecycleName, eventData?: any) { | ||
const publicRootInstance = this.getPublicRootInstance(); | ||
if (publicRootInstance) { | ||
(publicRootInstance as LifecycleWrapper).emitLifecycle(eventName, eventData); | ||
} | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
import React from 'react'; | ||
import { ReactNode } from 'react'; | ||
import createPageConfig from './createPageConfig'; | ||
// @ts-ignore | ||
export const render = (App: React.ComponentType<any>) => Page(createPageConfig(App)); | ||
export const render = (element: JSX.Element) => Page(createPageConfig(element)); | ||
@@ -15,1 +15,2 @@ let bridgeType = 'template'; | ||
export * from './factoryComponents'; | ||
export * from './lifecycles'; |
@@ -12,5 +12,6 @@ { | ||
"esModuleInterop": true, | ||
"moduleResolution": "node" | ||
"moduleResolution": "node", | ||
"jsx": "react" | ||
}, | ||
"include": ["./src/**/*.ts"] | ||
"include": ["./src/**/*"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
387516
98
1867
19