Skip to content

Commit

Permalink
refactor: improved handling of empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
orefalo committed Sep 25, 2024
1 parent 745637b commit f4b32b2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
18 changes: 9 additions & 9 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.10",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"svelte": "^4.2.18",
"svelte-check": "^3.8.0",
"svelte-splitpanes": "^0.8.2",
"tslib": "^2.6.3",
"typescript": "^5.4.5",
"vite": "^5.2.13"
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/kit": "^2.5.28",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"svelte": "^4.2.19",
"svelte-check": "^3.8.6",
"svelte-splitpanes": "^8.0.6",
"tslib": "^2.7.0",
"typescript": "^5.6.2",
"vite": "^5.4.8"
}
}
2 changes: 1 addition & 1 deletion src/comp/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
let touch: boolean;
function handleClick(e: MouseEvent | Touch, type: string) {
if (type == 'touch') {
if (type === 'touch') {
touch = true;
ripples.add({ x: e.pageX - locationX, y: e.pageY - locationY, size: scale_ratio });
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/comp/PrerenderedArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const element = document.getElementById(getIdFull(id));
if (element == null) {
if (!element) {
return null;
} else if (
!dev ||
Expand All @@ -34,7 +34,7 @@
var duplicatedChildren: Node[] | null = null;
if (area != null) {
if (area) {
const children = area.childNodes;
duplicatedChildren = Array.from(children).map(child => child.cloneNode(true));
}
Expand Down
13 changes: 7 additions & 6 deletions src/lib/Pane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@
*
* In the case of the object isn't initialized yet, calling this callbacks will do nothing.
*/
const carefullClientCallbacks = browser
? carefullCallbackSource(() => clientCallbacks)
: carefullCallbackSource(() => clientCallbacks);
: carefullCallbackSource(() => undefined);
// REACTIVE
const reportGivenSizeChangeSafe = (size: number) => {
// We put an extra check of `size != sz` here and not in the reactive statement, since we don't want a change
// of `sz` to trigger report.
if (size != sz) {
// This extra check (`size !== sz`) is here and not in the reactive statement, to prevent a trigger on `sz` mutations.
if (size !== sz) {
carefullClientCallbacks('reportGivenSizeChange')(size);
}
};
$: {
if (browser && size != null) {
if (browser && typeof size === 'number') {
reportGivenSizeChangeSafe(size);
}
}
Expand All @@ -84,7 +85,7 @@
sz: () => sz,
setSz: v => {
sz = v;
if (size != null && size != sz) {
if (typeof size === 'number' && size !== sz) {
size = sz;
}
},
Expand Down
23 changes: 12 additions & 11 deletions src/lib/Splitpanes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@
$: $isHorizontal = horizontal;
$: $showFirstSplitter = firstSplitter;
// used to complete rendering service side (SSR mode)
function ssrRegisterPaneSize(size: number | null) {
if (size == null) {
if (size === null) {
++ssrPaneUndefinedSizeCount;
} else {
ssrPaneDefinedSizeSum += size;
Expand Down Expand Up @@ -430,13 +431,13 @@
const paneElement = splitterPane.element;
let activeSplitterNode: Node | null = paneElement;
while (activeSplitterNode != null) {
while (activeSplitterNode) {
activeSplitterNode = activeSplitterNode.previousSibling;
if (activeSplitterNode && isSplitterElement(activeSplitterNode)) {
break;
}
}
if (activeSplitterNode == null) {
if (activeSplitterNode === null) {
console.error("Splitpane Error: Active splitter wasn't found!");
return; // Don't bind move event on error
}
Expand Down Expand Up @@ -570,7 +571,7 @@
for (let i = splitterIndex + 1; i < panes.length; i++) giveBest(panes[i]);
// at the end of the process, we must have that `leftSpare` is 0
if (leftSpare != 0) {
if (leftSpare !== 0) {
console.warn(
'Splitpanes: there is a left spare size after computation of splitter double click, which means there are issues on the size constains of the panes.'
);
Expand Down Expand Up @@ -608,7 +609,7 @@
let splittersTotalSizeBefore = 0;
let currentBeforeNode = activeSplitterElement.previousSibling;
while (currentBeforeNode != null) {
while (currentBeforeNode) {
if (isSplitterElement(currentBeforeNode)) {
splittersTotalSizeBefore += splitterSize(currentBeforeNode);
}
Expand All @@ -617,7 +618,7 @@
let splittersTotalSizeAfter = 0;
let currentAfterNode = activeSplitterElement.nextSibling;
while (currentAfterNode != null) {
while (currentAfterNode) {
if (isSplitterElement(currentAfterNode)) {
splittersTotalSizeAfter += splitterSize(currentAfterNode);
}
Expand Down Expand Up @@ -731,7 +732,7 @@
paneAfter = panes[paneAfterIndex];
}
if (paneBeforeIndex != null) {
if (typeof paneBeforeIndex === 'number') {
paneBefore.setSz(
Math.min(
Math.max(
Expand All @@ -742,7 +743,7 @@
)
);
}
if (paneAfterIndex != null) {
if (typeof paneAfterIndex === 'number') {
paneAfter.setSz(
Math.min(
Math.max(
Expand Down Expand Up @@ -885,7 +886,7 @@
for (let i = 0; i < panesCount; i++) {
const pane = panes[i];
const sz = pane.sz();
if (pane.givenSize == null) {
if (pane.givenSize === null) {
if (pane.isReady) {
undefinedSizesSum += sz;
if (sz >= pane.max()) ungrowable.push(pane);
Expand Down Expand Up @@ -932,7 +933,7 @@
for (let i = 0; i < panesCount; i++) {
const pane = panes[i];
if (pane.givenSize == null) {
if (!(typeof pane.givenSize === 'number')) {
// add the proportion of the newly added pane if has undefined size
const currentSz = pane.isReady ? pane.sz() : undefinedSizesNotReadySz;
const sz = Math.max(Math.min(currentSz * undefinedScaleFactor, pane.max()), pane.min());
Expand Down Expand Up @@ -1035,7 +1036,7 @@
const isPane = child?.classList.contains('splitpanes__pane');
if (isPane) {
const pane = panes.find(pane => pane.element === child);
if (pane != null) {
if (pane) {
pane.index = newPanes.length;
newPanes.push(pane);
} else {
Expand Down

0 comments on commit f4b32b2

Please sign in to comment.