lib/preact.rb in isomorfeus-preact-23.7.0.rc5 vs lib/preact.rb in isomorfeus-preact-23.8.0.rc1
- old
+ new
@@ -1,6 +1,7 @@
-# helpers: hash2, hash_get, hash_put
+# backtick_javascript: true
+# helpers: hash_get, hash_put
if RUBY_ENGINE == 'opal'
class VNode
# just a empty place holder to make is_a?(VNode) work
# internally using the js implementation
@@ -63,11 +64,10 @@
}
const EMPTY_OBJ = Object.create(null);
const EMPTY_ARR = [];
const slice = EMPTY_ARR.slice;
- const $has_own = Object.hasOwn || $call.bind(Object.prototype.hasOwnProperty);
function hash_fetch(hash, key) {
let val = $hash_get(hash, key);
return (val === undefined || val === null) ? nil : val;
}
@@ -82,11 +82,11 @@
let converted_value;
if (value == null || typeof(value) === 'undefined' ) { converted_value = nil; }
else if (typeof value.$$class !== 'undefined') { converted_value = value; }
else if (value instanceof Element || value instanceof Node) { converted_value = #{Browser::Element.new(`value`)}; }
if (typeof ref === "function") ref.$call(converted_value);
- else $hash_put(ref, "current", converted_value);
+ else ref.set("current", converted_value);
} catch (e) {
_catchError(e, vnode);
}
}
@@ -487,15 +487,15 @@
if (typeof oldValue === 'string') {
dom.style.cssText = oldValue = '';
}
if (value && value !== nil && value.$$is_hash) {
- value = value.$to_n();
+ value = Object.fromEntries(value);
}
if (oldValue && oldValue !== nil && oldValue.$$is_hash) {
- oldValue = oldValue.$to_n();
+ oldValue = Object.fromEntries(oldValue);
}
if (oldValue && oldValue !== nil) {
for (name in oldValue) {
if (!(value && name in value)) {
@@ -582,11 +582,11 @@
}
}
function diff_props(dom, new_props, old_props, is_svg, hydrate) {
#{`old_props`.each do |prop, value|
- `if (prop !== "children" && prop !== "key" && !(prop.$$is_string && $has_own(new_props.$$smap, prop))) { self.setProperty(dom, prop, null, value, is_svg); }`
+ `if (prop !== "children" && prop !== "key" && !(prop.$$is_string && new_props.has(prop))) { self.setProperty(dom, prop, null, value, is_svg); }`
nil
end
`new_props`.each do |prop, value|
if (`!hydrate || (prop[0] === 'o' && prop[1] === 'n' && prop[2] === '_')` || value.is_a?(Proc)) &&
`prop !== "children" && prop !== "key" && prop !== "value" && prop !== "checked"` &&
@@ -645,11 +645,11 @@
'http://www.w3.org/2000/svg',
// We know `newVNode.type` is a string
nodeType
);
} else {
- let np = newProps.$to_n();
+ let np = Object.fromEntries(newProps);
dom = document.createElement(
// We know `newVNode.type` is a string
nodeType,
np.is && np
);
@@ -668,24 +668,24 @@
}
} else {
// If excessDomChildren was not null, repopulate it with the current element's children:
excessDomChildren = excessDomChildren && slice.call(dom.childNodes);
- oldProps = oldVNode.props || $hash2([], {});
+ oldProps = oldVNode.props || new Map();
let oldHtml = hash_fetch(oldProps, "dangerouslySetInnerHTML");
let newHtml = hash_fetch(newProps, "dangerouslySetInnerHTML");
// During hydration, props are not diffed at all (including dangerouslySetInnerHTML)
// @TODO we should warn in debug mode when props don't match here.
if (!isHydrating) {
// But, if we are in a situation where we are using existing DOM (e.g. replaceNode)
// we should read the existing DOM attributes to diff them
if (excessDomChildren != null) {
- oldProps = $hash2([], {});
+ oldProps = new Map();
for (i = 0; i < dom.attributes.length; i++) {
- $hash_put(oldProps, dom.attributes[i].name, dom.attributes[i].value);
+ oldProps.set(dom.attributes[i].name, dom.attributes[i].value);
}
}
if (newHtml !== nil || oldHtml !== nil) {
// Avoid re-applying the same '__html' if it has not changed between re-render
@@ -730,12 +730,10 @@
}
// (as above, don't diff props during hydration)
if (!isHydrating) {
if (
- // instead of newProps["$key?"]("value")
- $has_own(newProps.$$smap, "value") &&
(i = hash_fetch(newProps, "value")) !== nil &&
// #2756 For the <progress>-element the initial value is 0,
// despite the attribute not being present. When the attribute
// is missing the progress bar is treated as indeterminate.
// To fix that we'll always update it when it is 0 for progress elements
@@ -745,15 +743,11 @@
// again, which triggers IE11 to re-evaluate the select value
(nodeType === 'option' && i !== hash_fetch(oldProps, "value")))
) {
self.setProperty(dom, 'value', i, hash_fetch(oldProps, "value"), false, null);
}
- if (
- $has_own(newProps.$$smap, "checked") &&
- (i = hash_fetch(newProps, "checked")) !== nil &&
- i !== dom.checked
- ) {
+ if ((i = hash_fetch(newProps, "checked")) !== nil && i !== dom.checked) {
self.setProperty(dom, 'checked', i, hash_fetch(oldProps, "checked"), false, null);
}
}
}
@@ -762,11 +756,11 @@
function validate_props(newType, newProps) {
if (newType.declared_props && newType.declared_props !== nil) {
#{
`newType.declared_props`.each do |prop, value|
- `if ($has_own(value.$$smap, "default") && !$has_own(newProps.$$smap, prop)) { #{`newProps`[prop] = value[:default]} }`
+ `if (value.has("default") && !newProps.has(prop)) { newProps.set(prop, value.get("default")) }`
nil
end
}
if (Opal.Isomorfeus.development) { #{`newType`.validate_props(`newProps`)} }
}
@@ -822,11 +816,11 @@
newVNode._component = c = newType.$new(newProps, componentContext);
if (provider && provider !== nil) provider.$sub(c);
c.props = newProps;
- if (c.state === nil || !c.state) c.state = $hash2([], {});
+ if (c.state === nil || !c.state) c.state = new Map();
c.context = componentContext;
c._globalContext = globalContext;
isNew = c._dirty = true;
c._renderCallbacks = [];
}
@@ -1053,11 +1047,11 @@
parentDom,
// Determine the new vnode tree and store it on the DOM element on
// our custom `_children` property.
vnode,
ov ? oldVNode : EMPTY_OBJ,
- $hash2([], {}),
+ new Map(),
parentDom.ownerSVGElement !== undefined,
nohy_reno ? [replaceNode] : ov ? null : parentDom.firstChild ? slice.call(parentDom.childNodes) : null,
commitQueue,
nohy_reno ? replaceNode : ov ? oldVNode._dom : parentDom.firstChild,
isHydrating
@@ -1218,10 +1212,10 @@
if (c.length > 0) { children = c; }
}
end
%x{
- if (children !== nil && children !== null) { $hash_put(normalized_props, "children", children); }
+ if (children !== nil && children !== null) { normalized_props.set("children", children); }
return self.createVNode(type, normalized_props, key, ref, null);
}
end
def _enqueue_render(c)