infamous
Version:
A CSS3D/WebGL UI library.
73 lines (56 loc) • 2.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _jamesBond = require("james-bond");
var _lowclass = _interopRequireDefault(require("lowclass"));
var _Mixin = _interopRequireDefault(require("lowclass/Mixin"));
var _utils = require("lowclass/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _Mixin.default)(Base => (0, _lowclass.default)('forwardProps').extends(Base, ({
Super,
Public,
Protected,
Private
}) => ({
connectedCallback() {
Super(this).connectedCallback && Super(this).connectedCallback();
Private(this).receivePropsFromObject();
},
disconnectedCallback() {
Super(this).disconnectedCallback && Super(this).disconnectedCallback();
Private(this).unreceivePropsFromObject();
},
private: {
propChangedCallback: (propName, value) => undefined,
receivePropsFromObject() {
const publicThis = Public(this);
this.propChangedCallback = (propName, value) => publicThis[propName] = value;
(0, _jamesBond.observe)(Protected(this).observedObject, this.getProps(), this.propChangedCallback, {// inherited: true, // XXX the 'inherited' option doesn't work in this case. Why?
});
},
unreceivePropsFromObject() {
(0, _jamesBond.unobserve)(Protected(this).observedObject, this.getProps(), this.propChangedCallback);
},
getProps() {
let result;
const props = Public(this).constructor.props;
if (Array.isArray(props)) result = props;else {
result = [];
if (typeof props === 'object') for (const prop in props) result.push(prop);
}
return result;
}
},
protected: {
get observedObject() {
throw new TypeError(`
The subclass using forwardProps must define a protected
observedObject property defining the object from which props
are forwarded.
`);
}
}
})));
exports.default = _default;
;