File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+ import Logger from 'mo/common/logger' ;
3+ import { IComponent } from './component' ;
4+ import { Controller } from './controller' ;
5+
6+ export function connect < S , P , C > (
7+ Service : IComponent ,
8+ View : React . ComponentType < P > ,
9+ Controller : Controller
10+ ) {
11+ return class Connector extends React . Component {
12+ state : { lastUpdated : number } ;
13+ constructor ( props ) {
14+ super ( props ) ;
15+ this . onChange = this . onChange . bind ( this ) ;
16+ this . state = {
17+ lastUpdated : Date . now ( ) ,
18+ } ;
19+ }
20+
21+ componentDidMount ( ) {
22+ Service . onUpdateState ( this . onChange ) ;
23+ }
24+
25+ onChange ( nextState : S ) {
26+ Logger . info ( nextState , Service . getState ( ) ) ;
27+ this . setState ( {
28+ lastUpdated : Date . now ( ) ,
29+ } ) ;
30+ }
31+
32+ render ( ) {
33+ const state = Service . getState ( ) ;
34+ return (
35+ < View
36+ { ...this . state }
37+ { ...state }
38+ { ...this . props }
39+ { ...Controller }
40+ />
41+ ) ;
42+ }
43+ } ;
44+ }
You can’t perform that action at this time.
0 commit comments