Module: Preact
- Defined in:
- lib/preact.rb,
lib/preact/ref.rb,
lib/preact/options.rb,
lib/preact/version.rb,
lib/preact/component/api.rb,
lib/preact/component/base.rb,
lib/preact/component/mixin.rb,
lib/preact/component/props.rb,
lib/preact/component/state.rb,
lib/preact/context_wrapper.rb,
lib/preact/component/params.rb,
lib/preact/component/elements.rb,
lib/preact/component/callbacks.rb,
lib/preact/component/resolution.rb,
lib/preact/component/initializer.rb,
lib/preact/native_constant_wrapper.rb,
lib/preact/component/native_component_constructor.rb,
lib/isomorfeus_preact/preact/function_component/api.rb,
lib/isomorfeus_preact/preact/function_component/base.rb,
lib/isomorfeus_preact/preact/function_component/mixin.rb,
lib/isomorfeus_preact/preact/function_component/initializer.rb,
lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb
Defined Under Namespace
Modules: Component, FunctionComponent
Classes: ContextWrapper, NativeConstantWrapper, Options, Ref
Constant Summary
collapse
- VERSION =
'10.6.8'
Class Method Summary
collapse
-
.clone_element(ruby_preact_element, props = nil, children = nil, &block) ⇒ Object
-
.create_context(const_name, default_value) ⇒ Object
-
.create_element(type, props = nil, children = nil, &block) ⇒ Object
-
.create_ref ⇒ Object
-
.hydrate(native_preact_element, container_node, replace_node) ⇒ Object
-
.location_hook(location) ⇒ Object
-
.render(native_preact_element, container_node, replace_node) ⇒ Object
-
.render_to_string(native_preact_element) ⇒ Object
-
.to_child_array(props_children) ⇒ Object
-
.unmount_component_at_node(element_or_query) ⇒ Object
Class Method Details
.clone_element(ruby_preact_element, props = nil, children = nil, &block) ⇒ Object
259
260
261
262
263
264
265
266
267
|
# File 'lib/preact.rb', line 259
def self.clone_element(ruby_preact_element, props = nil, children = nil, &block)
block_result = `null`
if block_given?
block_result = block.call
block_result = `null` unless block_result
end
native_props = props ? `Opal.Preact.to_native_preact_props(props)` : `null`
`Opal.global.Preact.cloneElement(ruby_preact_element.$to_n(), native_props, block_result)`
end
|
.create_context(const_name, default_value) ⇒ Object
269
270
271
272
273
274
275
276
|
# File 'lib/preact.rb', line 269
def self.create_context(const_name, default_value)
%x{
Opal.global[const_name] = Opal.global.Preact.createContext(default_value);
var new_const = #{Preact::ContextWrapper.new(`Opal.global[const_name]`)};
#{Object.const_set(const_name, `new_const`)};
return new_const;
}
end
|
.create_element(type, props = nil, children = nil, &block) ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/preact.rb', line 234
def self.create_element(type, props = nil, children = nil, &block)
%x{
const operabu = self.render_buffer;
let component = null;
let native_props = null;
if (typeof type.preact_component !== 'undefined') { component = type.preact_component; }
else { component = type; }
if (block !== nil) {
operabu.push([]);
// console.log("create_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString());
let block_result = block.$call();
if (block_result && block_result !== nil) { Opal.Preact.render_block_result(block_result); }
// console.log("create_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString());
children = operabu.pop();
} else if (children === nil) { children = []; }
else if (typeof children === 'string') { children = [children]; }
if (props && props !== nil) { native_props = self.to_native_preact_props(props); }
return Opal.global.Preact.createElement.apply(this, [component, native_props].concat(children));
}
end
|
.create_ref ⇒ Object
278
279
280
|
# File 'lib/preact.rb', line 278
def self.create_ref
Preact::Ref.new(`Opal.global.Preact.createRef()`)
end
|
.hydrate(native_preact_element, container_node, replace_node) ⇒ Object
282
283
284
|
# File 'lib/preact.rb', line 282
def self.hydrate(native_preact_element, container_node, replace_node)
`Opal.global.Preact.hydrate(native_preact_element, container_node)`
end
|
.location_hook(location) ⇒ Object
286
287
288
289
290
291
292
|
# File 'lib/preact.rb', line 286
def self.location_hook(location)
%x{
if (Opal.global.locationHook) { return Opal.global.locationHook; }
else if (Opal.global.staticLocationHook) { return Opal.global.staticLocationHook(location); }
else { #{raise "Wouter Location Hooks not imported!"}; }
}
end
|
.render(native_preact_element, container_node, replace_node) ⇒ Object
294
295
296
297
298
299
300
301
|
# File 'lib/preact.rb', line 294
def self.render(native_preact_element, container_node, replace_node)
if block_given?
`Opal.global.Preact.render(native_preact_element, container_node, function() { block.$call() })`
else
`Opal.global.Preact.render(native_preact_element, container_node)`
end
end
|
.render_to_string(native_preact_element) ⇒ Object
304
305
306
|
# File 'lib/preact.rb', line 304
def self.render_to_string(native_preact_element)
`Opal.global.Preact.renderToString(native_preact_element)`
end
|
.to_child_array(props_children) ⇒ Object
255
256
257
|
# File 'lib/preact.rb', line 255
def self.to_child_array(props_children)
`Opal.global.Preact.toChildArray(children)`
end
|
.unmount_component_at_node(element_or_query) ⇒ Object
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/preact.rb', line 309
def self.unmount_component_at_node(element_or_query)
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
element = `document.body.querySelector(element_or_query)`
elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
element = element_or_query.to_n
else
element = element_or_query
end
`Opal.global.Preact.render(null, element)`
end
|