clearwater 1.0.0.rc5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/clearwater/component.rb +1 -0
- data/lib/clearwater/version.rb +1 -1
- data/opal/clearwater/async_render.rb +47 -0
- data/opal/clearwater/black_box_node.rb +8 -3
- data/opal/clearwater/memoized_component.rb +20 -7
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f356e81cd74a9ac0752440a96ed8ea9fe8bfec0a3a46bdb3e048d221b07a549c
|
4
|
+
data.tar.gz: 8ccc1733f324d2d447078348cfa91044028825cabab89c7e6aa6a26687f91e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86d989057b70581df9173d58cd78810211dffa47f9190c0afd87d15b90c89a4e002166aa55aa5eb32199e6dccb4456b1509f0645f375c36235f649431070eac5
|
7
|
+
data.tar.gz: 7cf37024b21c8f339d32e56ec6abd8cd565776f6f28d0e02c2c6a28caf1da5640d300b90876b11cff94986d2725ba7f2533ad99df02a8596747dbdcdfbe15bc8
|
data/lib/clearwater/component.rb
CHANGED
data/lib/clearwater/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'clearwater/virtual_dom'
|
2
|
+
require 'clearwater/black_box_node'
|
3
|
+
|
4
|
+
module Clearwater
|
5
|
+
class AsyncRender
|
6
|
+
include Clearwater::BlackBoxNode
|
7
|
+
|
8
|
+
attr_reader :vnode
|
9
|
+
|
10
|
+
def initialize &content
|
11
|
+
if content.is_a? Array
|
12
|
+
warn "#{self.class} cannot operate on an Array, so it will use the first element. If you need to use an array, you can wrap it inside another element."
|
13
|
+
content = content.first
|
14
|
+
end
|
15
|
+
|
16
|
+
@content = content
|
17
|
+
end
|
18
|
+
|
19
|
+
# Specify a temporary node to use. It will be replaced with the content
|
20
|
+
# passed in.
|
21
|
+
def node
|
22
|
+
Component.span
|
23
|
+
end
|
24
|
+
|
25
|
+
def mount element
|
26
|
+
delayed_update nil, element
|
27
|
+
end
|
28
|
+
|
29
|
+
def update previous, element
|
30
|
+
delayed_update previous.vnode, element
|
31
|
+
end
|
32
|
+
|
33
|
+
def delayed_update from, element
|
34
|
+
Bowser.window.animation_frame do
|
35
|
+
@vnode = Component.sanitize_content(@content.call)
|
36
|
+
diff = VirtualDOM.diff from, @vnode
|
37
|
+
VirtualDOM.patch element.to_n, diff
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Component
|
43
|
+
def async_render &block
|
44
|
+
AsyncRender.new &block
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -50,7 +50,7 @@ module Clearwater
|
|
50
50
|
var self = this;
|
51
51
|
var node = #{create_element};
|
52
52
|
#{@delegate.mount(`node`)};
|
53
|
-
return node
|
53
|
+
return node['native'];
|
54
54
|
});
|
55
55
|
|
56
56
|
// virtual-dom update hook
|
@@ -58,13 +58,18 @@ module Clearwater
|
|
58
58
|
// node: a Bowser-wrapped version of the DOM node
|
59
59
|
Opal.defn(self, 'update', function(previous, node) {
|
60
60
|
var self = this;
|
61
|
+
|
61
62
|
if(self.delegate.$$class === previous.delegate.$$class) {
|
62
|
-
#{@delegate.update(`previous.delegate`, wrap(`node`))};
|
63
|
+
var result = #{@delegate.update(`previous.delegate`, wrap(`node`))};
|
64
|
+
|
65
|
+
if(result && result.$$class && #{Bowser::Element === `result`}) {
|
66
|
+
return #{`result`.to_n};
|
67
|
+
}
|
63
68
|
} else {
|
64
69
|
previous.destroy(#{wrap(`node`)});
|
65
70
|
var new_node = #{create_element};
|
66
71
|
#{@delegate.mount(`new_node`)};
|
67
|
-
return new_node
|
72
|
+
return new_node['native'];
|
68
73
|
}
|
69
74
|
});
|
70
75
|
|
@@ -23,6 +23,10 @@ module Clearwater
|
|
23
23
|
def destroy
|
24
24
|
end
|
25
25
|
|
26
|
+
def render
|
27
|
+
div
|
28
|
+
end
|
29
|
+
|
26
30
|
class Placeholder
|
27
31
|
include Clearwater::BlackBoxNode
|
28
32
|
|
@@ -61,13 +65,22 @@ module Clearwater
|
|
61
65
|
`#@vdom.rendered = true`
|
62
66
|
end
|
63
67
|
|
64
|
-
def update previous
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def update previous, element
|
69
|
+
# if we're looking at different classes, we need to start from scratch
|
70
|
+
if klass != previous.klass
|
71
|
+
previous.unmount element
|
72
|
+
|
73
|
+
new_element = render.create_element
|
74
|
+
mount new_element
|
75
|
+
new_element
|
76
|
+
else
|
77
|
+
@vdom = previous.vdom
|
78
|
+
@component = previous.component
|
79
|
+
|
80
|
+
if component.should_update?(*@args, &@block)
|
81
|
+
component.update(*@args, &@block)
|
82
|
+
@vdom.render component.render
|
83
|
+
end
|
71
84
|
end
|
72
85
|
end
|
73
86
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearwater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.5.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- opal/clearwater.rb
|
127
127
|
- opal/clearwater/application.rb
|
128
128
|
- opal/clearwater/application_registry.rb
|
129
|
+
- opal/clearwater/async_render.rb
|
129
130
|
- opal/clearwater/black_box_node.rb
|
130
131
|
- opal/clearwater/cached_render.rb
|
131
132
|
- opal/clearwater/cached_render/wrapper.rb
|
@@ -160,12 +161,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
161
|
version: '0'
|
161
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
163
|
requirements:
|
163
|
-
- - "
|
164
|
+
- - ">="
|
164
165
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
166
|
+
version: '0'
|
166
167
|
requirements: []
|
167
168
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.7.3
|
169
170
|
signing_key:
|
170
171
|
specification_version: 4
|
171
172
|
summary: Front-end Ruby web framework for fast, reasonable, and composable applications
|