isomorfeus-preact 22.9.0.rc2 → 22.9.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/document.rb +1 -8
- data/lib/browser/element/canvas.rb +17 -17
- data/lib/browser/element/media.rb +78 -78
- data/lib/browser/element.rb +0 -1
- data/lib/browser/event_target.rb +39 -39
- data/lib/browser/file_list.rb +125 -125
- data/lib/browser/location.rb +1 -1
- data/lib/browser/window.rb +0 -7
- data/lib/isomorfeus/preact/config.rb +0 -1
- data/lib/isomorfeus/preact/ssr.rb +11 -8
- data/lib/isomorfeus/preact/version.rb +1 -1
- data/lib/isomorfeus/preact/view_helper.rb +14 -22
- data/lib/isomorfeus/top_level.rb +3 -4
- data/lib/isomorfeus-preact.rb +0 -1
- metadata +6 -7
- data/lib/browser/iterable.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bba88069414d8ed45e76c087c9f6bb20006fdea62ac0b4769a7a0838d32a037
|
4
|
+
data.tar.gz: 9336d12827cea1fad40fdb178cfe8323758bb4fee4d88c767d7f2249a1e52e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05800ff4b025c00ea0db26a8e0d463eadcf5811fa95b088b0485f18b311c97c6bdc8483d8af8163404c8326de2a24083b11d9b89cf4692c9d35bb103f4133c3
|
7
|
+
data.tar.gz: f58cc4c176ead2e90b7ab0cdfc3af7080a55266b07fb128c796187ccb06b7000aa5be2fdb64d428fe3357d264ff987204616aaf8f368abe91319bc4efd0b7c1d
|
data/lib/browser/document.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
module Browser
|
2
|
-
class Element
|
3
|
-
element :canvas do
|
4
|
-
def context(type='2d')
|
5
|
-
Context.new(`#@native.getContext(#{type})`)
|
6
|
-
end
|
7
|
-
|
8
|
-
class Context
|
9
|
-
include DelegateNative
|
10
|
-
|
11
|
-
def initialize native
|
12
|
-
@native = native
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module Browser
|
2
|
+
class Element
|
3
|
+
element :canvas do
|
4
|
+
def context(type='2d')
|
5
|
+
Context.new(`#@native.getContext(#{type})`)
|
6
|
+
end
|
7
|
+
|
8
|
+
class Context
|
9
|
+
include DelegateNative
|
10
|
+
|
11
|
+
def initialize native
|
12
|
+
@native = native
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
module Browser
|
2
|
-
class Element
|
3
|
-
element :video, :audio do
|
4
|
-
def buffered
|
5
|
-
TimeRanges.new(`#@native.buffered`)
|
6
|
-
end
|
7
|
-
|
8
|
-
def played
|
9
|
-
TimeRanges.new(`#@native.played`)
|
10
|
-
end
|
11
|
-
|
12
|
-
def seekable
|
13
|
-
TimeRanges.new(`#@native.seekable`)
|
14
|
-
end
|
15
|
-
|
16
|
-
def network_state
|
17
|
-
case `#@native.networkState`
|
18
|
-
when `HTMLMediaElement.NETWORK_EMPTY` then :no_data
|
19
|
-
when `HTMLMediaElement.NETWORK_IDLE` then :idle
|
20
|
-
when `HTMLMediaElement.NETWORK_LOADING` then :loading
|
21
|
-
when `HTMLMediaElement.NETWORK_NO_SOURCE` then :no_source
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
element :video do
|
27
|
-
def fullscreen
|
28
|
-
fullscreen = %w(
|
29
|
-
requestFullScreen
|
30
|
-
requestFullscreen
|
31
|
-
webkitRequestFullScreen
|
32
|
-
webkitRequestFullscreen
|
33
|
-
mozRequestFullScreen
|
34
|
-
msRequestFullscreen
|
35
|
-
).find { |prop| `!!#@native[prop]` }
|
36
|
-
|
37
|
-
if fullscreen
|
38
|
-
`#@native[fullscreen]()`
|
39
|
-
else
|
40
|
-
warn "[#{self.class}] Cannot determine the method to full-screen a video"
|
41
|
-
super
|
42
|
-
end
|
43
|
-
end
|
44
|
-
alias request_fullscreen fullscreen
|
45
|
-
end
|
46
|
-
|
47
|
-
class TimeRanges
|
48
|
-
include Enumerable
|
49
|
-
|
50
|
-
def initialize native
|
51
|
-
@native = native
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_n
|
55
|
-
@native
|
56
|
-
end
|
57
|
-
|
58
|
-
def each
|
59
|
-
`#@native.length`.times do |i|
|
60
|
-
yield TimeRange.new(`#@native.start(i)`, `#@native.end(i)`)
|
61
|
-
end
|
62
|
-
|
63
|
-
self
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class TimeRange
|
68
|
-
attr_reader :start, :end
|
69
|
-
|
70
|
-
def initialize start, _end
|
71
|
-
@start = start
|
72
|
-
@end = _end
|
73
|
-
end
|
74
|
-
|
75
|
-
alias begin start
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
module Browser
|
2
|
+
class Element
|
3
|
+
element :video, :audio do
|
4
|
+
def buffered
|
5
|
+
TimeRanges.new(`#@native.buffered`)
|
6
|
+
end
|
7
|
+
|
8
|
+
def played
|
9
|
+
TimeRanges.new(`#@native.played`)
|
10
|
+
end
|
11
|
+
|
12
|
+
def seekable
|
13
|
+
TimeRanges.new(`#@native.seekable`)
|
14
|
+
end
|
15
|
+
|
16
|
+
def network_state
|
17
|
+
case `#@native.networkState`
|
18
|
+
when `HTMLMediaElement.NETWORK_EMPTY` then :no_data
|
19
|
+
when `HTMLMediaElement.NETWORK_IDLE` then :idle
|
20
|
+
when `HTMLMediaElement.NETWORK_LOADING` then :loading
|
21
|
+
when `HTMLMediaElement.NETWORK_NO_SOURCE` then :no_source
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
element :video do
|
27
|
+
def fullscreen
|
28
|
+
fullscreen = %w(
|
29
|
+
requestFullScreen
|
30
|
+
requestFullscreen
|
31
|
+
webkitRequestFullScreen
|
32
|
+
webkitRequestFullscreen
|
33
|
+
mozRequestFullScreen
|
34
|
+
msRequestFullscreen
|
35
|
+
).find { |prop| `!!#@native[prop]` }
|
36
|
+
|
37
|
+
if fullscreen
|
38
|
+
`#@native[fullscreen]()`
|
39
|
+
else
|
40
|
+
warn "[#{self.class}] Cannot determine the method to full-screen a video"
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias request_fullscreen fullscreen
|
45
|
+
end
|
46
|
+
|
47
|
+
class TimeRanges
|
48
|
+
include Enumerable
|
49
|
+
|
50
|
+
def initialize native
|
51
|
+
@native = native
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_n
|
55
|
+
@native
|
56
|
+
end
|
57
|
+
|
58
|
+
def each
|
59
|
+
`#@native.length`.times do |i|
|
60
|
+
yield TimeRange.new(`#@native.start(i)`, `#@native.end(i)`)
|
61
|
+
end
|
62
|
+
|
63
|
+
self
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class TimeRange
|
68
|
+
attr_reader :start, :end
|
69
|
+
|
70
|
+
def initialize start, _end
|
71
|
+
@start = start
|
72
|
+
@end = _end
|
73
|
+
end
|
74
|
+
|
75
|
+
alias begin start
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/browser/element.rb
CHANGED
data/lib/browser/event_target.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
module Browser
|
2
|
-
module EventTarget
|
3
|
-
# Add the block as a handler for the specified event name. Will use either
|
4
|
-
# `addEventListener` or `addListener` if they exist.
|
5
|
-
#
|
6
|
-
# @param event_name [String] the name of the event
|
7
|
-
# @return [Proc] the block to pass to `off` to remove this handler
|
8
|
-
# @yieldparam event [Browser::Event] the event object
|
9
|
-
def on event_name, &block
|
10
|
-
wrapper = proc { |event| block.call Event.new(event) }
|
11
|
-
|
12
|
-
if `#@native.addEventListener !== undefined`
|
13
|
-
`#@native.addEventListener(event_name, wrapper)`
|
14
|
-
elsif `#@native.addListener !== undefined`
|
15
|
-
`#@native.addListener(event_name, wrapper)`
|
16
|
-
else
|
17
|
-
warn "[Browser] Not entirely sure how to add an event listener to #{self}"
|
18
|
-
end
|
19
|
-
|
20
|
-
wrapper
|
21
|
-
end
|
22
|
-
|
23
|
-
# Remove an event handler
|
24
|
-
#
|
25
|
-
# @param event_name [String] the name of the event
|
26
|
-
# @block the handler to remove, as returned from `on`
|
27
|
-
def off event_name, &block
|
28
|
-
if `#@native.removeEventListener !== undefined`
|
29
|
-
`#@native.removeEventListener(event_name, block)`
|
30
|
-
elsif `#@native.removeListener !== undefined`
|
31
|
-
`#@native.removeListener(event_name, block)`
|
32
|
-
else
|
33
|
-
warn "[Browser] Not entirely sure how to remove an event listener from #{self}"
|
34
|
-
end
|
35
|
-
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
module Browser
|
2
|
+
module EventTarget
|
3
|
+
# Add the block as a handler for the specified event name. Will use either
|
4
|
+
# `addEventListener` or `addListener` if they exist.
|
5
|
+
#
|
6
|
+
# @param event_name [String] the name of the event
|
7
|
+
# @return [Proc] the block to pass to `off` to remove this handler
|
8
|
+
# @yieldparam event [Browser::Event] the event object
|
9
|
+
def on event_name, &block
|
10
|
+
wrapper = proc { |event| block.call Event.new(event) }
|
11
|
+
|
12
|
+
if `#@native.addEventListener !== undefined`
|
13
|
+
`#@native.addEventListener(event_name, wrapper)`
|
14
|
+
elsif `#@native.addListener !== undefined`
|
15
|
+
`#@native.addListener(event_name, wrapper)`
|
16
|
+
else
|
17
|
+
warn "[Browser] Not entirely sure how to add an event listener to #{self}"
|
18
|
+
end
|
19
|
+
|
20
|
+
wrapper
|
21
|
+
end
|
22
|
+
|
23
|
+
# Remove an event handler
|
24
|
+
#
|
25
|
+
# @param event_name [String] the name of the event
|
26
|
+
# @block the handler to remove, as returned from `on`
|
27
|
+
def off event_name, &block
|
28
|
+
if `#@native.removeEventListener !== undefined`
|
29
|
+
`#@native.removeEventListener(event_name, block)`
|
30
|
+
elsif `#@native.removeListener !== undefined`
|
31
|
+
`#@native.removeListener(event_name, block)`
|
32
|
+
else
|
33
|
+
warn "[Browser] Not entirely sure how to remove an event listener from #{self}"
|
34
|
+
end
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/browser/file_list.rb
CHANGED
@@ -1,125 +1,125 @@
|
|
1
|
-
module Browser
|
2
|
-
class FileList
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
# @param native [JS] the native FileList object to wrap
|
6
|
-
def initialize native
|
7
|
-
@native = `#{native} || []`
|
8
|
-
@files = length.times.each_with_object([]) { |index, array|
|
9
|
-
array[index] = File.new(`#@native[index]`)
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
# @param index [Integer] the index of the file in the list
|
14
|
-
# @return [Browser::FileList::File] the file at the specified index
|
15
|
-
def [] index
|
16
|
-
@files[index]
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [Integer] the number of files in this list
|
20
|
-
def length
|
21
|
-
`#@native.length`
|
22
|
-
end
|
23
|
-
alias size length
|
24
|
-
|
25
|
-
# Call the given block for each file in the list
|
26
|
-
#
|
27
|
-
# @yieldparam file [Browser::FileList::File]
|
28
|
-
def each &block
|
29
|
-
@files.each do |file|
|
30
|
-
block.call file
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Convert this FileList into an array
|
35
|
-
def to_a
|
36
|
-
@files.dup # Don't return a value that can mutate our internal state
|
37
|
-
end
|
38
|
-
alias to_ary to_a
|
39
|
-
|
40
|
-
# @return [String] a string representation of this FileList
|
41
|
-
def to_s
|
42
|
-
@files.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
# An individual item in a FileList
|
46
|
-
class File
|
47
|
-
attr_reader :data
|
48
|
-
|
49
|
-
# @param native [JS] the native File object to wrap
|
50
|
-
def initialize native
|
51
|
-
@native = native
|
52
|
-
@data = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [String] the filename
|
56
|
-
def name
|
57
|
-
`#@native.name`
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Integer] the size of this file on disk
|
61
|
-
def size
|
62
|
-
`#@native.size`
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [String] the MIME type of the file, detected by the browser
|
66
|
-
def type
|
67
|
-
`#@native.type`
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [Time] the timestamp of the file
|
71
|
-
def last_modified
|
72
|
-
`#@native.lastModifiedDate`
|
73
|
-
end
|
74
|
-
|
75
|
-
# Read the file from disk into memory
|
76
|
-
#
|
77
|
-
# @return [Promise] a promise that resolves when finished loading and
|
78
|
-
# rejects if an error occurs while loading.
|
79
|
-
def read
|
80
|
-
promise = Promise.new
|
81
|
-
reader = FileReader.new
|
82
|
-
reader.on :load do
|
83
|
-
result = reader.result
|
84
|
-
|
85
|
-
@data = result
|
86
|
-
promise.resolve result
|
87
|
-
end
|
88
|
-
|
89
|
-
reader.on :error do
|
90
|
-
promise.reject reader.result
|
91
|
-
end
|
92
|
-
|
93
|
-
reader.read_as_binary_string self
|
94
|
-
|
95
|
-
promise
|
96
|
-
end
|
97
|
-
|
98
|
-
# Convert to the native object
|
99
|
-
#
|
100
|
-
# @return [JS.HTMLElement] the underlying native element
|
101
|
-
def to_n
|
102
|
-
@native
|
103
|
-
end
|
104
|
-
|
105
|
-
# The object that reads the file from disk.
|
106
|
-
#
|
107
|
-
# @api private
|
108
|
-
class FileReader
|
109
|
-
include EventTarget
|
110
|
-
|
111
|
-
def initialize
|
112
|
-
@native = `new FileReader()`
|
113
|
-
end
|
114
|
-
|
115
|
-
def result
|
116
|
-
`#@native.result`
|
117
|
-
end
|
118
|
-
|
119
|
-
def read_as_binary_string file
|
120
|
-
`#@native.readAsBinaryString(#{file.to_n})`
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
1
|
+
module Browser
|
2
|
+
class FileList
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
# @param native [JS] the native FileList object to wrap
|
6
|
+
def initialize native
|
7
|
+
@native = `#{native} || []`
|
8
|
+
@files = length.times.each_with_object([]) { |index, array|
|
9
|
+
array[index] = File.new(`#@native[index]`)
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param index [Integer] the index of the file in the list
|
14
|
+
# @return [Browser::FileList::File] the file at the specified index
|
15
|
+
def [] index
|
16
|
+
@files[index]
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Integer] the number of files in this list
|
20
|
+
def length
|
21
|
+
`#@native.length`
|
22
|
+
end
|
23
|
+
alias size length
|
24
|
+
|
25
|
+
# Call the given block for each file in the list
|
26
|
+
#
|
27
|
+
# @yieldparam file [Browser::FileList::File]
|
28
|
+
def each &block
|
29
|
+
@files.each do |file|
|
30
|
+
block.call file
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convert this FileList into an array
|
35
|
+
def to_a
|
36
|
+
@files.dup # Don't return a value that can mutate our internal state
|
37
|
+
end
|
38
|
+
alias to_ary to_a
|
39
|
+
|
40
|
+
# @return [String] a string representation of this FileList
|
41
|
+
def to_s
|
42
|
+
@files.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
# An individual item in a FileList
|
46
|
+
class File
|
47
|
+
attr_reader :data
|
48
|
+
|
49
|
+
# @param native [JS] the native File object to wrap
|
50
|
+
def initialize native
|
51
|
+
@native = native
|
52
|
+
@data = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] the filename
|
56
|
+
def name
|
57
|
+
`#@native.name`
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Integer] the size of this file on disk
|
61
|
+
def size
|
62
|
+
`#@native.size`
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [String] the MIME type of the file, detected by the browser
|
66
|
+
def type
|
67
|
+
`#@native.type`
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Time] the timestamp of the file
|
71
|
+
def last_modified
|
72
|
+
`#@native.lastModifiedDate`
|
73
|
+
end
|
74
|
+
|
75
|
+
# Read the file from disk into memory
|
76
|
+
#
|
77
|
+
# @return [Promise] a promise that resolves when finished loading and
|
78
|
+
# rejects if an error occurs while loading.
|
79
|
+
def read
|
80
|
+
promise = Promise.new
|
81
|
+
reader = FileReader.new
|
82
|
+
reader.on :load do
|
83
|
+
result = reader.result
|
84
|
+
|
85
|
+
@data = result
|
86
|
+
promise.resolve result
|
87
|
+
end
|
88
|
+
|
89
|
+
reader.on :error do
|
90
|
+
promise.reject reader.result
|
91
|
+
end
|
92
|
+
|
93
|
+
reader.read_as_binary_string self
|
94
|
+
|
95
|
+
promise
|
96
|
+
end
|
97
|
+
|
98
|
+
# Convert to the native object
|
99
|
+
#
|
100
|
+
# @return [JS.HTMLElement] the underlying native element
|
101
|
+
def to_n
|
102
|
+
@native
|
103
|
+
end
|
104
|
+
|
105
|
+
# The object that reads the file from disk.
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
class FileReader
|
109
|
+
include EventTarget
|
110
|
+
|
111
|
+
def initialize
|
112
|
+
@native = `new FileReader()`
|
113
|
+
end
|
114
|
+
|
115
|
+
def result
|
116
|
+
`#@native.result`
|
117
|
+
end
|
118
|
+
|
119
|
+
def read_as_binary_string file
|
120
|
+
`#@native.readAsBinaryString(#{file.to_n})`
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/browser/location.rb
CHANGED
data/lib/browser/window.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
class PreactSSR
|
3
|
-
def
|
4
|
-
rendered_tree = new(component_name, props, session_id, location, locale).render
|
5
|
-
[rendered_tree, Isomorfeus.store.get_state, NanoCSS.instance.renderer[:raw]]
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(component_name, props, session_id, location, locale = nil)
|
3
|
+
def initialize(component_name, props, session_id, location, locale)
|
9
4
|
@session_id = session_id
|
10
5
|
@component_name = component_name
|
11
6
|
@props = props
|
@@ -13,12 +8,14 @@ module Isomorfeus
|
|
13
8
|
@locale = locale
|
14
9
|
end
|
15
10
|
|
16
|
-
def render
|
11
|
+
def render(skip_ssr)
|
17
12
|
Isomorfeus.browser_location = Browser::Location.new(@location)
|
18
13
|
Isomorfeus.current_locale = @locale
|
19
14
|
NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
|
20
15
|
Isomorfeus.init_store
|
21
16
|
Isomorfeus.store.clear!
|
17
|
+
Isomorfeus.store.dispatch(type: 'I18N_MERGE', data: { locale: @locale, domain: Isomorfeus.i18n_domain })
|
18
|
+
return '' if skip_ssr
|
22
19
|
c = Isomorfeus.current_user
|
23
20
|
if c.respond_to?(:reload)
|
24
21
|
Thread.current[:isomorfeus_user] = LocalSystem.new
|
@@ -28,7 +25,13 @@ module Isomorfeus
|
|
28
25
|
Thread.current[:isomorfeus_user] = c
|
29
26
|
end
|
30
27
|
end
|
31
|
-
|
28
|
+
render_component_to_string(@component_name, @props)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_component_to_string(component_name, props)
|
32
|
+
component = component_name.is_a?(String) ? self.class.const_get(component_name) : component_name
|
33
|
+
::Preact._vnode_id = 0
|
34
|
+
::Preact.render_to_string(::Preact.create_element(component, props))
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -4,46 +4,38 @@ module Preact
|
|
4
4
|
base.include Isomorfeus::AssetManager::ViewHelper
|
5
5
|
end
|
6
6
|
|
7
|
-
def cached_mount_component(component_name, props = {}, skip_ssr: false,
|
7
|
+
def cached_mount_component(component_name, props = {}, skip_ssr: false, refresh: false)
|
8
8
|
key = "#{Isomorfeus.current_user}#{component_name}#{props}"
|
9
9
|
if !Isomorfeus.development? && !refresh
|
10
10
|
render_result, @_ssr_styles, status = component_cache.fetch(key)
|
11
11
|
Isomorfeus.ssr_response_status = status
|
12
12
|
return render_result if render_result
|
13
13
|
end
|
14
|
-
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr
|
14
|
+
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr)
|
15
15
|
status = ssr_response_status
|
16
16
|
component_cache.store(key, render_result, ssr_styles, status) if status >= 200 && status < 300
|
17
17
|
render_result
|
18
18
|
end
|
19
19
|
|
20
|
-
def mount_component(component_name, props = {}, skip_ssr: false
|
20
|
+
def mount_component(component_name, props = {}, skip_ssr: false)
|
21
21
|
ssr_start_time = Time.now if Isomorfeus.development?
|
22
22
|
@ssr_styles = nil
|
23
|
+
locale = props.delete(:locale)
|
23
24
|
render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
|
24
|
-
|
25
|
-
|
26
|
-
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
25
|
+
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
26
|
+
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
27
27
|
|
28
|
-
|
28
|
+
rendered_tree, application_state, @_ssr_styles = Isomorfeus::TopLevel.mount_component(component_name, props, Thread.current[:isomorfeus_session_id], location, locale, skip_ssr)
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
35
|
-
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
36
|
-
else
|
37
|
-
if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
38
|
-
render_result << " data-iso-usids=#{Oj.dump(Isomorfeus.current_user.sid.to_s, mode: :strict)}"
|
39
|
-
end
|
40
|
-
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
30
|
+
render_result << " data-iso-hydrated='true'" unless skip_ssr
|
31
|
+
if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
32
|
+
render_result << " data-iso-usids=#{Oj.dump(Isomorfeus.current_user.sid.to_s, mode: :strict)}"
|
41
33
|
end
|
34
|
+
render_result << '>'
|
35
|
+
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
42
36
|
render_result << '</div>'
|
43
|
-
|
44
|
-
|
45
|
-
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
46
|
-
end
|
37
|
+
render_result = "<script type='application/javascript'>\nServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}\n</script>\n" << render_result
|
38
|
+
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
47
39
|
render_result
|
48
40
|
end
|
49
41
|
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -117,10 +117,9 @@ module Isomorfeus
|
|
117
117
|
Isomorfeus.top_component = top
|
118
118
|
end
|
119
119
|
else
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
::Preact.render_to_string(::Preact.create_element(component, props))
|
120
|
+
def mount_component(component, props, session_id, location, locale, skip_ssr = false)
|
121
|
+
rendered_tree = Isomorfeus::PreactSSR.new(component, props, session_id, location, locale).render(skip_ssr)
|
122
|
+
[rendered_tree, Isomorfeus.store.get_state, NanoCSS.instance.renderer[:raw]]
|
124
123
|
end
|
125
124
|
end
|
126
125
|
end
|
data/lib/isomorfeus-preact.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-preact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 22.9.0.
|
4
|
+
version: 22.9.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 22.9.0.
|
61
|
+
version: 22.9.0.rc4
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 22.9.0.
|
68
|
+
version: 22.9.0.rc4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: isomorfeus-redux
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 22.9.0.
|
75
|
+
version: 22.9.0.rc4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 22.9.0.
|
82
|
+
version: 22.9.0.rc4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: isomorfeus-puppetmaster
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,7 +140,6 @@ files:
|
|
140
140
|
- lib/browser/event_target.rb
|
141
141
|
- lib/browser/file_list.rb
|
142
142
|
- lib/browser/history.rb
|
143
|
-
- lib/browser/iterable.rb
|
144
143
|
- lib/browser/location.rb
|
145
144
|
- lib/browser/window.rb
|
146
145
|
- lib/data_uri.rb
|
data/lib/browser/iterable.rb
DELETED