lib/preact.rb in isomorfeus-preact-22.9.0.rc7 vs lib/preact.rb in isomorfeus-preact-22.9.0.rc8

- old
+ new

@@ -1186,47 +1186,10 @@ else _create_vnode(vnode.type, normalized_props, key || vnode.key, ref || vnode.ref, nil) end end - def create_element(type, props = nil, children = nil, &block) - if props - if props.is_a?(Hash) - normalized_props = props.dup - key = normalized_props.delete(:key) - ref = normalized_props.delete(:ref) - else - children = props - normalized_props = {} - key = nil - ref = nil - end - else - normalized_props = {} - key = nil - ref = nil - end - - if block_given? - pr = render_buffer - pr.push([]) - block_result = block.call - children = pr.pop - if Preact.is_renderable?(block_result) - children.push(block_result) - end - end - - normalized_props[:children] = children unless children.nil? - - if RUBY_ENGINE == 'opal' - `self.createVNode(type, normalized_props, key, ref, null)` - else - _create_vnode(type, normalized_props, key, ref, nil) - end - end - def create_context(const_name, default_value = nil) context = Preact::Context.new(default_value) Object.const_set(const_name, context) end @@ -1245,10 +1208,44 @@ if RUBY_ENGINE == 'opal' attr_accessor :_vnode_id attr_accessor :render_buffer attr_accessor :rerender_queue + def create_element(type, props = nil, children = nil, &block) + if props + if props.is_a?(Hash) + normalized_props = props.dup + key = normalized_props.delete(:key) + ref = normalized_props.delete(:ref) + else + children = props + normalized_props = {} + key = nil + ref = nil + end + else + normalized_props = {} + key = nil + ref = nil + end + + if block_given? + pr = render_buffer + pr.JS.push([]) + block_result = block.call + children = pr.JS.pop() + if Preact.is_renderable?(block_result) + children.JS.push(block_result) + end + end + + %x{ + if (children !== nil && children !== null) { #{normalized_props[:children] = children} } + 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++`)) `setTimeout(self.process)` end end @@ -1317,9 +1314,41 @@ Thread.current[:@_isomorfeus_preact_rerender_queue] = i end def _create_vnode(type, props, key, ref, original) VNode.new(type, props, key, ref, original) + end + + def create_element(type, props = nil, children = nil, &block) + if props + if props.is_a?(Hash) + normalized_props = props.dup + key = normalized_props.delete(:key) + ref = normalized_props.delete(:ref) + else + children = props + normalized_props = {} + key = nil + ref = nil + end + else + normalized_props = {} + key = nil + ref = nil + end + + if block_given? + pr = render_buffer + pr.push([]) + block_result = block.call + children = pr.pop + if Preact.is_renderable?(block_result) + children.push(block_result) + end + end + + normalized_props[:children] = children unless children.nil? + _create_vnode(type, normalized_props, key, ref, nil) end def _encode_entities(input) s = input.to_s return s unless ENCODED_ENTITIES.match?(s)