Skip to content

Commit

Permalink
Removed redundant PagyJSON type
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jan 16, 2022
1 parent 6089e43 commit 22f57d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
17 changes: 8 additions & 9 deletions lib/javascripts/pagy-dev.js

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions lib/javascripts/pagy-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ const Pagy = {
init(arg) {
const target = arg instanceof Element ? arg : document;
const elements = target.querySelectorAll("[data-pagy-json]");
for (const element of elements) {
for (const el of elements) {
try {
const jsonString = element.getAttribute("data-pagy-json");
const [keyword, ...args] = JSON.parse(jsonString);
const [keyword, ...args] = JSON.parse(el.getAttribute("data-pagy-json"));
if (keyword === "nav") {
Pagy.initNav(element, args);
Pagy.initNav(el, args);
}
else if (keyword === "combo") {
Pagy.initCombo(element, args);
Pagy.initCombo(el, args);
}
else if (keyword === "selector") {
Pagy.initSelector(element, args);
Pagy.initSelector(el, args);
}
else {
Pagy.initWarn(element, `Illegal PagyJSON keyword: expected "nav"|"combo"|"selector", got "${keyword}"`);
Pagy.initWarn(el, `Illegal PagyJSON keyword: expected "nav"|"combo"|"selector", got "${keyword}"`);
}
}
catch (err) {
Pagy.initWarn(element, err);
Pagy.initWarn(el, err);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/javascripts/pagy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions src/pagy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type PagyJSON = readonly ["nav", ...NavArgs] | ["combo", ...ComboArgs] | ["selector", ...SelectorArgs]
type NavArgs = readonly [Tags, Sequels, null|LabelSequels, string?]
type ComboArgs = readonly [string, string?]
type SelectorArgs = readonly [number, string, string?]
Expand All @@ -20,20 +19,19 @@ const Pagy = {
init(arg?:Element|never) {
const target = arg instanceof Element ? arg : document;
const elements = target.querySelectorAll("[data-pagy-json]");
for (const element of elements) {
for (const el of elements) {
try {
const jsonString = element.getAttribute("data-pagy-json") as string;
const [keyword, ...args] = JSON.parse(jsonString) as PagyJSON;
const [keyword, ...args] = JSON.parse(el.getAttribute("data-pagy-json") as string);
if (keyword === "nav") {
Pagy.initNav(element as NavElement, args as NavArgs);
Pagy.initNav(el as NavElement, args as NavArgs);
} else if (keyword === "combo") {
Pagy.initCombo(element, args as ComboArgs);
Pagy.initCombo(el, args as ComboArgs);
} else if (keyword === "selector") {
Pagy.initSelector(element, args as SelectorArgs);
Pagy.initSelector(el, args as SelectorArgs);
} else {
Pagy.initWarn(element, `Illegal PagyJSON keyword: expected "nav"|"combo"|"selector", got "${keyword}"`);
Pagy.initWarn(el, `Illegal PagyJSON keyword: expected "nav"|"combo"|"selector", got "${keyword}"`);
}
} catch (err) { Pagy.initWarn(element, err) }
} catch (err) { Pagy.initWarn(el, err) }
}
},

Expand Down

0 comments on commit 22f57d2

Please sign in to comment.