UNPKG

react-native-mdcore

Version:
35 lines (28 loc) 915 B
import * as Utils from '../libs/utils' export default class StyleSheet { static create(creator = (_theme, ..._args) => { }) { return new StyleSheet(Utils.isFunction(creator) ? creator : () => creator) } static _getThemeId(theme) { return theme ? theme.__id : null } constructor(creator) { this._creator = creator this._theme = undefined this._themeId = undefined this._args = undefined this._style = undefined } get(theme = null, ...args) { if (this._shouldRenewCache(theme, args)) { this._theme = theme this._themeId = this.constructor._getThemeId(theme) this._args = args this._style = this._creator(this._theme, ...this._args) } return this._style } _shouldRenewCache(theme = null, args) { return theme !== this._theme || this.constructor._getThemeId(theme) !== this._themeId || !Utils.deepEqual(args, this._args) } }