UNPKG

@joist/element

Version:

Intelligently apply styles to WebComponents

118 lines 6.87 kB
import { __esDecorate, __runInitializers } from "tslib"; import { assert } from "chai"; import { attrChanged } from "./attr-changed.js"; import { attr } from "./attr.js"; import { element } from "./element.js"; it("should call specific attrbute callback", () => { let args = []; let MyElement = (() => { let _classDecorators = [element({ tagName: "attr-changed-1", })]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _classSuper = HTMLElement; let _instanceExtraInitializers = []; let _test_decorators; let _test_initializers = []; let _test_extraInitializers = []; let _onTestChanged_decorators; var MyElement = class extends _classSuper { static { _classThis = this; } static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _test_decorators = [attr()]; _onTestChanged_decorators = [attrChanged("test")]; __esDecorate(this, null, _test_decorators, { kind: "accessor", name: "test", static: false, private: false, access: { has: obj => "test" in obj, get: obj => obj.test, set: (obj, value) => { obj.test = value; } }, metadata: _metadata }, _test_initializers, _test_extraInitializers); __esDecorate(this, null, _onTestChanged_decorators, { kind: "method", name: "onTestChanged", static: false, private: false, access: { has: obj => "onTestChanged" in obj, get: obj => obj.onTestChanged }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); MyElement = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); } #test_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _test_initializers, "hello")); get test() { return this.#test_accessor_storage; } set test(value) { this.#test_accessor_storage = value; } onTestChanged(name, oldValue, newValue) { console.log("onTestChanged", name, oldValue, newValue); args = [name, oldValue, newValue]; } constructor() { super(...arguments); __runInitializers(this, _test_extraInitializers); } }; return MyElement = _classThis; })(); const el = new MyElement(); document.body.append(el); assert.deepEqual(args, ["test", null, "hello"]); el.setAttribute("test", "world"); assert.deepEqual(args, ["test", "hello", "world"]); el.remove(); }); it("should call callback for multiple attributes", () => { const args = []; let MyElement = (() => { let _classDecorators = [element({ tagName: "attr-changed-2", })]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _classSuper = HTMLElement; let _instanceExtraInitializers = []; let _test1_decorators; let _test1_initializers = []; let _test1_extraInitializers = []; let _test2_decorators; let _test2_initializers = []; let _test2_extraInitializers = []; let _onTestChanged_decorators; var MyElement = class extends _classSuper { static { _classThis = this; } static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _test1_decorators = [attr()]; _test2_decorators = [attr()]; _onTestChanged_decorators = [attrChanged("test1", "test2")]; __esDecorate(this, null, _test1_decorators, { kind: "accessor", name: "test1", static: false, private: false, access: { has: obj => "test1" in obj, get: obj => obj.test1, set: (obj, value) => { obj.test1 = value; } }, metadata: _metadata }, _test1_initializers, _test1_extraInitializers); __esDecorate(this, null, _test2_decorators, { kind: "accessor", name: "test2", static: false, private: false, access: { has: obj => "test2" in obj, get: obj => obj.test2, set: (obj, value) => { obj.test2 = value; } }, metadata: _metadata }, _test2_initializers, _test2_extraInitializers); __esDecorate(this, null, _onTestChanged_decorators, { kind: "method", name: "onTestChanged", static: false, private: false, access: { has: obj => "onTestChanged" in obj, get: obj => obj.onTestChanged }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); MyElement = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); } #test1_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _test1_initializers, "hello")); get test1() { return this.#test1_accessor_storage; } set test1(value) { this.#test1_accessor_storage = value; } #test2_accessor_storage = (__runInitializers(this, _test1_extraInitializers), __runInitializers(this, _test2_initializers, "world")); get test2() { return this.#test2_accessor_storage; } set test2(value) { this.#test2_accessor_storage = value; } onTestChanged(attr, oldValue, newValue) { args.push([attr, oldValue, newValue]); } constructor() { super(...arguments); __runInitializers(this, _test2_extraInitializers); } }; return MyElement = _classThis; })(); const el = new MyElement(); document.body.append(el); assert.deepEqual(args, [ ["test1", null, "hello"], ["test2", null, "world"], ]); el.setAttribute("test1", "world"); assert.deepEqual(args, [ ["test1", null, "hello"], ["test2", null, "world"], ["test1", "hello", "world"], ]); el.remove(); }); //# sourceMappingURL=attr-changed.test.js.map