跳到主要内容
版本:0.9.0-beta.2

Class: Component<S>

molecule.react.Component

Type parameters

NameType
Sany

Hierarchy

Implements

Constructors

constructor

new Component<S>()

Type parameters

NameType
Sany

Overrides

GlobalEvent.constructor

Defined in

src/react/component.ts:45

Properties

_event

Private _event: EventEmitter

Defined in

src/react/component.ts:43


state

Protected Abstract state: S

Defined in

src/react/component.ts:42

Methods

count

count(name): number

Count the service event

Parameters

NameTypeDescription
namestringEvent name

Returns

number

Inherited from

GlobalEvent.count

Defined in

src/common/event/eventBus.ts:28


emit

emit(name, ...args): void

Emit the service event

Parameters

NameTypeDescription
namestringEvent name
...argsanyArguments

Returns

void

Inherited from

GlobalEvent.emit

Defined in

src/common/event/eventBus.ts:20


forceUpdate

forceUpdate(): void

Force to update the Component

Returns

void

Implementation of

IComponent.forceUpdate

Defined in

src/react/component.ts:79


getState

getState(): S

Get the Component state

Returns

S

Implementation of

IComponent.getState

Defined in

src/react/component.ts:83


onUpdateState

onUpdateState(callback): void

Listen to the Component state update event

Parameters

NameType
callback(prevState: S, nextState: S) => void

Returns

void

Implementation of

IComponent.onUpdateState

Defined in

src/react/component.ts:71


removeOnUpdateState

removeOnUpdateState(): void

Remove the Component update event listening

Returns

void

Implementation of

IComponent.removeOnUpdateState

Defined in

src/react/component.ts:75


render

render(nextState?): void

Initiative notify the component to render the view by the state

Parameters

NameType
nextState?S

Returns

void

Implementation of

IComponent.render

Defined in

src/react/component.ts:67


setState

setState(values, callback?): void

Set the state values, and notify the view component to re render

Parameters

NameTypeDescription
valuesPartial<S>update target state values
callback?(prevState: S, nextState: S) => void-

Returns

void

Implementation of

IComponent.setState

Defined in

src/react/component.ts:54


subscribe

subscribe(name, callback): void

Subscribe the service event

Parameters

NameTypeDescription
namestring | string[]Event name
callbackFunctionCallback function

Returns

void

Inherited from

GlobalEvent.subscribe

Defined in

src/common/event/eventBus.ts:11


unsubscribe

unsubscribe(name): void

Unsubscribe the specific event

Parameters

NameTypeDescription
nameanyThe event name

Returns

void

Inherited from

GlobalEvent.unsubscribe

Defined in

src/common/event/eventBus.ts:37