/**
 * React-Type-R component base class. Overrides React component.
 */ import * as React from 'react' ; import { Record , Store , CallbacksByEvents , mixinRules , define , mixins , definitions , tools , Messenger } from 'type-r' ; import Link from './link' ; import onDefine , { TypeSpecs , EmptyPropsChangeTokensCtor } from './define' ; @ define ( { PropsChangeTokens : EmptyPropsChangeTokensCtor } ) @ definitions ( { state : mixinRules . merge , State : mixinRules . value , store : mixinRules . merge , Store : mixinRules . value , props : mixinRules . merge , context : mixinRules . merge , childContext : mixinRules . merge , pureRender : mixinRules . protoValue } ) @ mixinRules ( { componentWillMount : mixinRules . classLast , componentDidMount : mixinRules . classLast , componentWillReceiveProps : mixinRules . classLast , componentWillUpdate : mixinRules . classLast , componentDidUpdate : mixinRules . classLast , componentWillUnmount : mixinRules . classFirst , shouldComponentUpdate : mixinRules . some , getChildContext : mixinRules . defaults } ) @ mixins ( Messenger ) export class Component < P , S extends Record = Record > extends React . Component < P , S > { cid : string ; static state ? : TypeSpecs | typeof Record ; static store ? : TypeSpecs | typeof Store ; static props ? : TypeSpecs ; static context ? : TypeSpecs ; static childContext ? : TypeSpecs ; static pureRender ? : boolean ; private _disposed : boolean ; private static propTypes : any ; private static defaultProps : any ; private static contextTypes : any ; private static childContextTypes : any ; private PropsChangeTokens : Function ; static extend : ( spec : object , statics ? : object ) => Component < any > ; linkAt ( key ) { return ( this . state as any ) . linkAt ( key ) ; } linkAll ( ... keys ) ; linkAll ( ) { const { state } = this as any ; return state . linkAll . apply ( state , arguments ) ; } linkPath ( path ) { return ( this . state as any ) . linkPath ( path ) ; } get links ( ) { return ( this . state as any ) . _links ; } static onDefine = onDefine ; readonly state : S ; readonly store ? : Store ; constructor ( props ? , context ? ) { super ( props , context ) ; this . _initializeState ( ) ; } _initializeState ( ) { ( this as any ) . state = null ; } assignToState ( x , key ) { this . state . assignFrom ( { [ key ] : x } ) ; } isMounted : ( ) => boolean ; on : ( events : string | CallbacksByEvents , callback , context ? ) => this ; once : ( events : string | CallbacksByEvents , callback , context ? ) => this ; off : ( events ? : string | CallbacksByEvents , callback ? , context ? ) => this ; trigger : ( name : string , a ? , b ? , c ? , d ? , e ? ) => this ; stopListening : ( source ? : Messenger , a ? : string | CallbacksByEvents , b ? : Function ) => this ; listenTo : ( source : Messenger , a : string | CallbacksByEvents , b ? : Function ) => this ; listenToOnce : ( source : Messenger , a : string | CallbacksByEvents , b ? : Function ) => this ; dispose : ( ) => void ; componentWillUnmount ( ) { this . dispose ( ) ; } /**
     * Performs transactional update for both props and state.
     * Suppress updates during the transaction, and force update aftewards.
     * Wrapping the sequence of changes in a transactions guarantees that
     * React component will be updated _after_ all the changes to the
     * both props and local state are applied.
     */ transaction ( fun ) { var shouldComponentUpdate = this . shouldComponentUpdate , isRoot = shouldComponentUpdate !== returnFalse ; if ( isRoot ) { this . shouldComponentUpdate = returnFalse ; } const { state , store } = this , withStore = store ? state => store . transaction ( ( ) => fun ( state ) ) : fun ; state ? state . transaction ( withStore ) : withStore ( state ) ; if ( isRoot ) { this . shouldComponentUpdate = shouldComponentUpdate ; this . asyncUpdate ( ) ; } } asyncUpdate ( ) { this . shouldComponentUpdate === returnFalse || this . _disposed || this . forceUpdate ( ) ; } } function returnFalse ( ) { return false ; } Object . defineProperty ( Component . prototype , 'isMounted' , { value : function isMounted ( ) { return ! this . _disposed ; } } ) ;