| 18 | } |
| 19 | |
| 20 | class Component<P, S> implements ComponentInst<P, S> { |
| 21 | public static defaultProps: {} |
| 22 | static getDerivedStateFromError? (error?): object | null |
| 23 | state: Readonly<S> |
| 24 | props: Readonly<P> & Readonly<Props> |
| 25 | prevProps: P |
| 26 | prevState: S |
| 27 | prevContext: object |
| 28 | _parentComponent: Component<any, any> |
| 29 | vnode: CompositeComponent |
| 30 | context: any |
| 31 | _dirty = true |
| 32 | _disable = true |
| 33 | _pendingStates: any[] = [] |
| 34 | _pendingCallbacks: Function[] = [] |
| 35 | refs: Refs |
| 36 | isReactComponent: Object |
| 37 | _afterScheduleEffect = false |
| 38 | hooks: Hook[] = [] |
| 39 | effects: HookEffect[] = EMPTY_CHILDREN |
| 40 | layoutEffects: HookEffect[] = EMPTY_CHILDREN |
| 41 | |
| 42 | constructor (props?: P, context?: any) { |
| 43 | if (!this.state) { |
| 44 | this.state = {} as S |
| 45 | } |
| 46 | this.props = props || ({} as P) |
| 47 | this.context = context || EMPTY_OBJ |
| 48 | this.refs = {} |
| 49 | } |
| 50 | |
| 51 | setState<K extends keyof S> ( |
| 52 | state: |
| 53 | | ((prevState: Readonly<S>, props: P) => Pick<S, K> | S) |
| 54 | | (Pick<S, K> | S), |
| 55 | callback?: () => void |
| 56 | ): void { |
| 57 | if (state) { |
| 58 | this._pendingStates.push(state) |
| 59 | } |
| 60 | if (isFunction(callback)) { |
| 61 | this._pendingCallbacks.push(callback) |
| 62 | } |
| 63 | if (!this._disable) { |
| 64 | enqueueRender(this) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | getState () { |
| 69 | // tslint:disable-next-line:no-this-assignment |
| 70 | const { _pendingStates, state, props } = this |
| 71 | if (!_pendingStates.length) { |
| 72 | return state |
| 73 | } |
| 74 | const stateClone = clone(state) |
| 75 | const queue = _pendingStates.concat() |
| 76 | this._pendingStates.length = 0 |
| 77 | queue.forEach((nextState) => { |
nothing calls this directly
no outgoing calls
no test coverage detected