Skip to content

Commit

Permalink
Make sure that we set empty references as Maybe.Nothing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign committed Jan 25, 2025
1 parent 6b3fb70 commit af8e65a
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 18 deletions.
6 changes: 4 additions & 2 deletions runtime/src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export const bracketAccess = (array, index, just, nothing) => {

// This sets the references to an element or component. The current
// value is always a `Maybe`
export const setRef = (value, just) => (element) => {
if (value.current._0 !== element) {
export const setRef = (value, just, nothing) => (element) => {
if (element === null) {
value.current = new nothing();
} else {
value.current = new just(element);
}
};
Expand Down
2 changes: 1 addition & 1 deletion spec/compilers/component_instance_access
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ export const
return C(`div`, {
"onClick": d
}, [C(K, {
_: H(c, I)
_: H(c, I, J)
})])
};
2 changes: 1 addition & 1 deletion spec/compilers/component_instance_access_2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export const
a = C(new F()),
H = () => {
return B(G, {
_: D(a, E)
_: D(a, E, F)
})
};
4 changes: 2 additions & 2 deletions spec/compilers/component_instance_access_ref
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const
}, []);
(_ ? _(b) : null);
return D(`div`, {
ref: E(a, I)
ref: E(a, I, J)
})
},
L = () => {
Expand All @@ -74,6 +74,6 @@ export const
return D(`div`, {
"onClick": d
}, [D(K, {
_: E(c, I)
_: E(c, I, J)
})])
};
2 changes: 1 addition & 1 deletion spec/compilers/html_attribute_ref
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const
G = () => {
const a = B(new F());
return C(`div`, {
ref: D(a, E)
ref: D(a, E, F)
})
};
2 changes: 1 addition & 1 deletion spec/compilers/test_with_reference
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default () => {
const a = C(new G());
return (() => {
D(`button`, {
ref: E(a, H)
ref: E(a, H, G)
});
return F(a.current, new G())
})()
Expand Down
2 changes: 1 addition & 1 deletion spec/compilers/test_with_reference_component
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default () => {
const b = E(new H());
return (() => {
C(J, {
_: F(b, I)
_: F(b, I, H)
});
return G(b.current, new H())
})()
Expand Down
12 changes: 6 additions & 6 deletions src/assets/runtime.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/runtime_test.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/compilers/html_component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Mint

node.ref.try do |ref|
attributes["_"] =
js.call(Builtin::SetRef, [[ref] of Item, just])
js.call(Builtin::SetRef, [[ref] of Item, just, nothing])
end

if component.async?
Expand Down
2 changes: 1 addition & 1 deletion src/compilers/html_element.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module Mint

node.ref.try do |ref|
attributes["ref"] =
js.call(Builtin::SetRef, [[ref] of Item, just])
js.call(Builtin::SetRef, [[ref] of Item, just, nothing])
end

js.call(Builtin::CreateElement, [
Expand Down

0 comments on commit af8e65a

Please sign in to comment.