reactive-di-observable
Version:
reactive-di dependency injection - observable plugins
78 lines (58 loc) • 3.06 kB
JavaScript
;
exports.__esModule = true;
var _reactiveDi = require('reactive-di');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/*:: import type {
ArgumentHelper,
Container,
Annotation
} from 'reactive-di'*/
/*:: import type {
CreateStyleSheet,
StyleSheet
} from 'reactive-di-observable'*/
var ThemeProvider = function (_BaseProvider) {
_inherits(ThemeProvider, _BaseProvider);
function ThemeProvider /*:: <Styles: Object, Classes: Object>*/(annotation /*: Annotation*/, container /*: Container*/, createStyleSheet /*: CreateStyleSheet<Styles, mixed>*/) {
_classCallCheck(this, ThemeProvider);
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation, container));
_this.type = 'theme';
_this._id = annotation;
_this._helper = container.createArgumentHelper(annotation);
_this._createStyleSheet = createStyleSheet;
return _this;
}
ThemeProvider.prototype.update = function update() {
var value = this._helper.createObject();
var styles /*: Styles*/ = value.__css;
if (this._sheet) {
this._sheet.detach();
}
var sheet /*: StyleSheet<Classes>*/ = this._sheet = this._createStyleSheet(styles, this._id);
sheet.attach();
Object.assign(value, sheet.classes);
this.value = value;
};
ThemeProvider.prototype.dispose = function dispose() {
_BaseProvider.prototype.dispose.call(this);
if (this._sheet) {
this._sheet.detach();
}
};
return ThemeProvider;
}(_reactiveDi.BaseProvider);
var ThemePlugin = function () {
function ThemePlugin /*:: <Styles: Object>*/(createStyleSheet /*: CreateStyleSheet<Styles, mixed>*/) {
_classCallCheck(this, ThemePlugin);
this.kind = 'theme';
this._createStyleSheet = createStyleSheet;
}
ThemePlugin.prototype.createProvider = function createProvider(annotation /*: Annotation*/, container /*: Container*/) {
return new ThemeProvider(annotation, container, this._createStyleSheet);
};
return ThemePlugin;
}();
exports.default = ThemePlugin;
//# sourceMappingURL=ThemePlugin.js.map