Skip to content

Commit

Permalink
perf(root): root inject viewid
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Mar 20, 2018
1 parent 895a5eb commit af65f8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-mobx-vm",
"version": "0.1.7",
"description": "View & Model are mixed now via react mobx",
"description": "View & Model are mixed now via react mobx.",
"scripts": {
"babel": "rimraf packages && babel srcPackages -d packages -D",
"rollup": "rimraf dist && rollup -c --silent",
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@commitlint/cli": "^6.1.0",
"@commitlint/config-conventional": "^6.1.0",
"@commitlint/config-conventional": "^6.1.3",
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-plugin-external-helpers": "^6.22.0",
Expand Down
11 changes: 11 additions & 0 deletions src/Model/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
toJS
} from 'mobx'
import _ from 'lodash'
import getViewId from '../utils/increaseId'

/**
*
Expand Down Expand Up @@ -105,6 +106,16 @@ export default class Root {
}

constructor(init = {}) {
Object.defineProperty(
this, 'viewId',
{
value: getViewId(),
enumerable: false,
configurable: true,
writable: true
}
)

this.assignShallow(init)
}

Expand Down
16 changes: 4 additions & 12 deletions src/decorator/bindView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import m from './modelComp'
import { observer } from 'mobx-react'
import getViewId from '../utils/increaseId'

export function getView(Model) {
if (typeof Model === 'function') {
Expand All @@ -16,10 +15,10 @@ export function getView(Model) {
}

/**
*
*
* 用于绑定 ViewModel 中与 Model 中对应的 View
* @export
* @param {Function|ReactClass} View
* @param {Function|ReactClass} View
* @public
* @example
* class View extends React.Component {
Expand Down Expand Up @@ -50,18 +49,11 @@ export default function bindView(View) {
{
value: View,
enumerable: false,
configurable: true
configurable: true,
writable: true
}
)

Object.defineProperty(
State.prototype, 'viewId',
{
value: getViewId(),
enumerable: false,
configurable: true
}
)
return State
}
}

0 comments on commit af65f8c

Please sign in to comment.