lib/preact.rb in isomorfeus-preact-22.10.0.rc2 vs lib/preact.rb in isomorfeus-preact-22.11.0.rc1

- old
+ new

@@ -648,22 +648,22 @@ } } else { // If excessDomChildren was not null, repopulate it with the current element's children: excessDomChildren = excessDomChildren && slice.call(dom.childNodes); - oldProps = oldVNode.props || Opal.Hash.$new(); + oldProps = oldVNode.props || Opal.hash(); let oldHtml = oldProps["$[]"]("dangerouslySetInnerHTML"); let newHtml = 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 = Opal.Hash.$new(); + oldProps = Opal.hash(); for (i = 0; i < dom.attributes.length; i++) { oldProps["$[]="](dom.attributes[i].name, dom.attributes[i].value); } } @@ -795,38 +795,41 @@ clearProcessingException = c._processingException = c._pendingError; } else { // Instantiate the new component // validate props validate_props(newType, newProps); - // The check above verifies that newType is suppose to be constructed + newProps.$freeze(); + // The check above verifies that newType is supposed to be constructed 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 = Opal.Hash.$new(); + if (c.state === nil || !c.state) c.state = Opal.hash(); c.context = componentContext; c._globalContext = globalContext; isNew = c._dirty = true; c._renderCallbacks = []; } // Invoke get_derived_state_from_props - if (c._nextState === nil) { + if (!c._nextState || c._nextState === nil) { c._nextState = c.state; } if (!isNew) { validate_props(newType, newProps); } + newProps.$freeze(); if (c["$respond_to?"]("get_derived_state_from_props")) { if (c._nextState == c.state) { c._nextState = c._nextState.$dup(); } c._nextState["$merge!"](c.$get_derived_state_from_props(newProps, c._nextState)); } oldProps = c.props; oldState = c.state; + c._nextState.$freeze(); // Invoke pre-render lifecycle methods if (isNew) { if (c["$respond_to?"]("component_did_mount")) { c._renderCallbacks.push(c.$component_did_mount); @@ -1005,11 +1008,10 @@ "$==": eql = function(other) { return vnode_eql(vnode, other); }, "$eql?": eql, "$nil?": is_nil, "$$is_vnode": true }; - return vnode; } self.render = function(vnode, parentDom, replaceNode) { // We abuse the `replaceNode` parameter in `hydrate()` to signal if we are in @@ -1041,11 +1043,11 @@ parentDom, // Determine the new vnode tree and store it on the DOM element on // our custom `_children` property. vnode, ov ? oldVNode : EMPTY_OBJ, - Opal.Hash.$new(), + Opal.hash(), 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 @@ -1214,11 +1216,11 @@ return self.createVNode(type, normalized_props, key, ref, null); } end def _enqueue_render(c) - if ((`!c._dirty` && (`c._dirty = true`) && rerender_queue.push(c) && `!self.process._rerenderCount++`)) + if ((`!c._dirty` && (`c._dirty = true`) && (rerender_queue << c) && `!self.process._rerenderCount++`)) `setTimeout(self.process)` end end def _render_element(component, props, &block) @@ -1318,10 +1320,10 @@ return str.empty? ? nil : str end def _render_element(element, props, &block) pr = Preact.render_buffer - pr[pr.length-1].push(create_element(element, props, nil, &block)) + pr[pr.length-1] << create_element(element, props, nil, &block) nil end def render_to_string(vnode, context = nil) _init_render