Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
fix: up Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
zeromake committed Jul 26, 2017
1 parent 19c0640 commit 2a78b36
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class Component {
// 把旧的状态保存起来
this.prevState = extend({}, s);
}
// 把新的state和并到this.state
if (typeof state === "function") {
const newState = state(s, this.props);
if (newState) {
Expand All @@ -153,7 +154,7 @@ export class Component {
this._renderCallbacks = this._renderCallbacks || [];
this._renderCallbacks.push(callback);
}
// 更新dom
// 异步队列更新dom,通过enqueueRender方法可以保证在一个任务栈下多次setState但是只会发生一次render
enqueueRender(this);
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IKeyValue } from "./types";
* @see http://jasonformat.com/wtf-is-jsx
* @public
*/
export function h(nodeName: string | Component | ((props?: IKeyValue, state?: IKeyValue, context?: IKeyValue) => VNode), attributes: IKeyValue, ...args: Array<VNode|string>) {
export function h(nodeName: string | typeof Component | ((props?: IKeyValue, state?: IKeyValue, context?: IKeyValue) => VNode), attributes: IKeyValue, ...args: Array<VNode|string>) {
// 初始化子元素列表
const stack: Array<VNode|string> = [];
const children: Array<VNode|string> = [];
Expand Down
1 change: 1 addition & 0 deletions src/render-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function enqueueRender(component: Component) {

/**
* 根据Component队列更新dom。
* 可以setState后直接执行这个方法强制同步更新dom
*/
export function rerender() {
let p: Component | undefined;
Expand Down

0 comments on commit 2a78b36

Please sign in to comment.