FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: gracefully fail on duplicate registration by castastrophe · Pull Request #1728 · patternfly/patternfly-elements · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
10e4c1c
feat: Pull out polyfill and pfelement updates
castastrophe Jul 27, 2021
7e0bdc4
feat: Update changelog
castastrophe Jul 27, 2021
5c408ce
feat: Bring in update to parsing tool
castastrophe Jul 27, 2021
5c2924c
Merge branch 'master' into feat-gracefully-fail-dupe-definition
castastrophe Jul 27, 2021
3e38de7
feat: Polyfills
castastrophe Jul 27, 2021
85a9cf1
Merge branch 'feat-gracefully-fail-dupe-definition' of github.com:pat…
castastrophe Jul 27, 2021
5c556a8
feat: Add comment for polyfill file
castastrophe Jul 27, 2021
084616b
feat: Update polyfill and todos
castastrophe Jul 27, 2021
45ed990
feat: Pull out styles/html into separate PR #1730
castastrophe Jul 27, 2021
fa80d0e
feat: Update todos and polyfills listing
castastrophe Jul 27, 2021
9661d50
feat: Update test cases
castastrophe Jul 28, 2021
3eadea0
feat: Split out tests into 2
castastrophe Jul 28, 2021
f33dfda
feat: Pull out context tests into separate file
castastrophe Jul 28, 2021
b766315
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
6033d34
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
f26f608
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
f88becd
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
ca96895
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
fca9d79
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
dbe3b05
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
26afc47
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
59f9f2d
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
fc5de3c
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
b92836c
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
4ee48f0
Branch was auto-updated with the latest.
github-actions[bot] Jul 28, 2021
File filter

Filter by extension

Filter by extension .html  (3) .js  (2) .json  (1) .md  (1) All 4 file types selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions CHANGELOG-1.x.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 1.10.2 (2021)
# 1.11.0 (2021)

- [](https://github.com/patternfly/patternfly-elements/commit/) fix: Jump links parseInt for IE11
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: Graceful failure for component registry
- [5f88c39](https://github.com/patternfly/patternfly-elements/commit/5f88c3963f8a6c13a9aeba6e9f664678453d46ce) fix: Jump links parseInt for IE11

# 1.10.1 (2021-07-12)

Expand Down
2 changes: 1 addition & 1 deletion docs/_data/todos.json

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion elements/pfelement/src/pfelement.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,23 @@ class PFElement extends HTMLElement {
pfe._createCache();
pfe._populateCache(pfe);
pfe._validateProperties();
window.customElements.define(pfe.tag, pfe);

try {
window.customElements.define(pfe.tag, pfe);
} catch (err) {
// Capture the class currently using this tag in the registry
const prevDefinition = window.customElements.get(pfe.tag);

// Check if the previous definition's version matches this one
if (prevDefinition && prevDefinition.version !== pfe.version) {
this.warn(
`${pfe.tag} was registered at version ${prevDefinition.version}; cannot register version ${pfe.version}.`
);
}

// @TODO Should this error be reported to the console?
if (err && err.message) this.log(err.message);
}

if (PFElement.trackPerformance()) {
try {
Expand Down
3 changes: 2 additions & 1 deletion elements/pfelement/test/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
'pfelement_properties_test.html',
'pfelement_cascade_attribute_test.html',
'pfelement_logging_test.html',
'pfelement_context_test.html',
// @TODO: Deprecate after 1.0
'old-test/pfelement_test.html',
'old-test/pfelement_cascade_attribute_test.html',
'old-test/pfelement_logging_test.html'
'old-test/pfelement_logging_test.html',
]);

</script>
Expand Down
230 changes: 230 additions & 0 deletions elements/pfelement/test/pfelement_context_test.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="/components/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="/components/web-component-tester/browser.js"></script>
</head>

<body>

<pfelement>
This is the element content.
</pfelement>

<script type="module">
import PFElement from "../dist/pfelement.js";

const colors = ["red", "yellow", "blue"];

class TestElement extends PFElement {
static get tag() {
return "pfe-test-element"
}

static get version() {
return "1.0";
}

get html() {
return `
<style>:host{--context:dark;}</style>
<div>Test Element</div>
`;
}

constructor() {
super(TestElement, { type: PFElement.PfeTypes.Content });
}
}

PFElement.create(TestElement);

class TestChildElement extends PFElement {
static get tag() {
return "pfe-test-child-element"
}

get html() {
return `
<div>Test Child Element</div>
`;
}

constructor() {
super(TestChildElement, { type: PFElement.PfeTypes.Content });
}
}

PFElement.create(TestChildElement);

suite('<pfelement>', () => {
teardown(() => {
const testElement = document.getElementById("test-element");

if (!testElement) return;

document.body.removeChild(testElement);
});

test("it should default to the provided --context variable in the component's stylesheet", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element";
document.body.appendChild(testElement);

assert.equal(testElement.getAttribute("on"), "dark");
});

test("it should update the on attribute if style with --context is manually added after upgrade", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element";
document.body.appendChild(testElement);

testElement.setAttribute("style", "color: pink; --context: light;");

assert.equal(testElement.getAttribute("on"), "light");
});

test("it should favor context attribute over the --context variable", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element";
document.body.appendChild(testElement);

testElement.setAttribute("context", "saturated");
testElement.setAttribute("style", "color: pink; --context: light;");

assert.equal(testElement.getAttribute("on"), "saturated");
});

test("it should update the on attribute if context is manually added after upgrade", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element";
document.body.appendChild(testElement);

document.querySelector("#test-element").setAttribute("context", "light");

assert.equal(testElement.getAttribute("on"), "light");
});

test("it should push down the context to children", done => {
const testElement = document.createElement("pfe-test-element");
const testChildElement = document.createElement("pfe-test-child-element");

testElement.id = "test-element";
testChildElement.id = "test-child-element";

testElement.appendChild(testChildElement);
document.body.appendChild(testElement);

flush(() => {
assert.equal(testChildElement.getAttribute("on"), "dark");
done();
});
});

test("it should push an attribute override context down to the children", done => {
const testElement = document.createElement("pfe-test-element");
const testChildElement = document.createElement("pfe-test-child-element");

testElement.id = "test-element";
testChildElement.id = "test-child-element";

testElement.appendChild(testChildElement);
document.body.appendChild(testElement);

// Add the context information
testElement.setAttribute("context", "light");

flush(() => {
assert.equal(testChildElement.getAttribute("on"), "light");
done();
});
});

test("it should push a variable override context down to the children", done => {
const testElement = document.createElement("pfe-test-element");
const testChildElement = document.createElement("pfe-test-child-element");

testElement.id = "test-element";
testChildElement.id = "test-child-element";

testElement.appendChild(testChildElement);
document.body.appendChild(testElement);

// Add the context information
testElement.setAttribute("style", "--context: light;");

flush(() => {
assert.equal(testChildElement.getAttribute("on"), "light");
done();
});
});

test("it should favor child's context if set via variable --context", () => {
const testElement = document.createElement("pfe-test-element");
const testChildElement = document.createElement("pfe-test-child-element");

testElement.id = "test-element";
testChildElement.id = "test-child-element";

testElement.appendChild(testChildElement);
document.body.appendChild(testElement);

// Add the context information
testChildElement.setAttribute("style", "--context: light;");

assert.equal(testChildElement.getAttribute("on"), "light");
});

test("it should favor child's context if the child has context set", () => {
const testElement = document.createElement("pfe-test-element");
const testChildElement = document.createElement("pfe-test-child-element");

testElement.id = "test-element";
testChildElement.id = "test-child-element";

testElement.appendChild(testChildElement);
document.body.appendChild(testElement);

// Add the context information
testChildElement.setAttribute("context", "light");

assert.equal(testChildElement.getAttribute("on"), "light");
});

// @TODO Deprecated for 1.0
test("it should update the on attribute if style with --theme is manually added after upgrade", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element";
document.body.appendChild(testElement);

assert.equal(testElement.getAttribute("on"), "dark");
testElement.setAttribute("style", "color: pink; --theme: light;");
assert.equal(testElement.getAttribute("on"), "light");
});

// @TODO Deprecated for 1.0
test("it should update the on and context attributes if pfe-theme is manually added after upgrade", () => {
const testElement = document.createElement("pfe-test-element");

testElement.id = "test-element-theme";
document.body.appendChild(testElement);

document.querySelector("#test-element-theme").setAttribute("pfe-theme", "light");

assert.equal(testElement.getAttribute("on"), "light");
assert.equal(testElement.getAttribute("context"), "light");
});

});
</script>
</body>

</html>
Loading

Back | FazBrowse Home | New Git URL