Skip to content

Commit

Permalink
feat(@areslabs/wx-react): 减少对外暴露的接口,相应的增强RNBaseComponent reactCompHel…
Browse files Browse the repository at this point in the history
…per的能力
  • Loading branch information
ykforerlang committed Dec 16, 2019
1 parent ef72810 commit 6024ce9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/wx-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@areslabs/wx-react",
"version": "2.0.0",
"version": "2.0.1",
"description": "微信版本的React",
"files": [
"package.json",
Expand Down
22 changes: 22 additions & 0 deletions packages/wx-react/src/AllComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

import instanceManager from "./InstanceManager";
import tackleWithStyleObj from './tackleWithStyleObj'
import { VIEW, SCROLL, OUTERTEXT}from './styleType'

import shallowEqual from './shallowEqual'

Expand Down Expand Up @@ -106,4 +108,24 @@ export class HocComponent extends Component {
}

export class RNBaseComponent {

getWxInst() {
return instanceManager.getWxInstByUUID(this.__diuu__)
}

transformViewStyle(style){
return tackleWithStyleObj(style, VIEW)
}

transformScrollViewStyle(style) {
return tackleWithStyleObj(style, SCROLL)
}

transformTextStyle(style) {
return tackleWithStyleObj(style, OUTERTEXT)
}

transformStyle(style) {
return tackleWithStyleObj(style)
}
}
3 changes: 2 additions & 1 deletion packages/wx-react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import WxNormalComp from './WxNormalComp'
import tackleWithStyleObj, {parseElement, flattenStyle} from './tackleWithStyleObj'
import styleType from './styleType'
import instanceManager from './InstanceManager'
import {getPropsMethod, reactCompHelper} from './util'
import {getPropsMethod} from './util'
import reactCompHelper from './reactCompHelper'
import {unstable_batchedUpdates, renderPage, renderApp} from './UpdateStrategy'


Expand Down
47 changes: 47 additions & 0 deletions packages/wx-react/src/reactCompHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import instanceManager from "./InstanceManager";

/**
* Copyright (c) Areslabs.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

export default function reactCompHelper(obj) {
obj.properties = {
...obj.properties,
diuu: null,
}

const rawAttached = obj.attached
obj.attached = function () {
const rawData = this.data
Object.defineProperty(this, 'data', {
get: function () {
const compInst = instanceManager.getCompInstByUUID(rawData.diuu);
return {
...rawData,
...compInst.props
}
},
})
rawAttached && rawAttached.call(this)
instanceManager.setWxCompInst(this.data.diuu, this)
}

const rawDetached = obj.detached
obj.detached = function () {
rawDetached && rawDetached.call(this)
instanceManager.removeUUID(this.data.diuu)
}

if (!obj.methods) {
obj.methods = {}
}
obj.methods.getReactComp = function () {
return instanceManager.getCompInstByUUID(this.data.diuu)
}

return obj
}
31 changes: 0 additions & 31 deletions packages/wx-react/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,4 @@ export function cleanPageComp(pageComp) {
invokeWillUnmount(allChildren)
}

export function reactCompHelper(obj) {
obj.properties = {
...obj.properties,
diuu: null,
}

const rawAttached = obj.attached
obj.attached = function () {
const rawData = this.data
Object.defineProperty(this, 'data', {
get: function () {
const compInst = instanceManager.getCompInstByUUID(rawData.diuu);
return {
...rawData,
...compInst.props
}
},
})
rawAttached && rawAttached.call(this)
instanceManager.setWxCompInst(this.data.diuu, this)
}

const rawDetached = obj.detached
obj.detached = function () {
rawDetached && rawDetached.call(this)
instanceManager.removeUUID(this.data.diuu)
}

return obj
}


0 comments on commit 6024ce9

Please sign in to comment.