| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import Calendar from '../Calendar'
- import View from '../View'
- import Theme from '../theme/Theme'
- import { DateEnv } from '../datelib/env'
- import { isPropsEqual, assignTo, EqualityFuncHash } from '../util/object'
- let guid = 0
- export interface ComponentContext {
- options: any
- dateEnv: DateEnv
- theme: Theme
- calendar: Calendar
- view?: View
- }
- export default class Component<PropsType> {
- equalityFuncs: EqualityFuncHash
- uid: string
- props: PropsType | null // non-null signals that a render happened
- // context vars
- context: ComponentContext
- dateEnv: DateEnv
- theme: Theme
- view: View
- calendar: Calendar
- isRtl: boolean
- constructor(context: ComponentContext) {
- this.uid = String(guid++)
- this.context = context
- this.dateEnv = context.dateEnv
- this.theme = context.theme
- this.view = context.view
- this.calendar = context.calendar
- this.isRtl = this.opt('dir') === 'rtl'
- }
- static addEqualityFuncs(newFuncs: EqualityFuncHash) {
- this.prototype.equalityFuncs = assignTo(
- {},
- this.prototype.equalityFuncs,
- newFuncs
- )
- }
- opt(name) {
- return this.context.options[name]
- }
- receiveProps(props: PropsType) {
- if (!this.props || !isPropsEqual(this.props, props, this.equalityFuncs)) {
- this.props = props
- this.render(props)
- }
- }
- protected render(props: PropsType) {
- }
- // after destroy is called, this component won't ever be used again
- destroy() {
- }
- }
|