clearwater 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5db375a0696ec574fae4263215dfde5ba4b0af97
4
- data.tar.gz: bdf36853856326f64742bd6f2d075727f1514713
3
+ metadata.gz: 2c9a840ae557659a4f0df595834d8ff94590de64
4
+ data.tar.gz: af9368086749443938d6964c7fe85bc134a8185e
5
5
  SHA512:
6
- metadata.gz: 50d6c60d11599bcfcd3935c7ebccfb86c11f6f85b1873c998e18ccd5b4b5f2107b5b0f3ff1d609d2dc22edd0fe25f19cfdecc735750820eaf7fa142711d69e84
7
- data.tar.gz: 28a9a411ffe93d08ea8a9c0749574ac0ade1b144645013d00d60b2e5893c1fac58c5432d1cd358b2486a31933988e409368d45024a7556f21695780b2fccb16f
6
+ metadata.gz: 5191ef0e82b48af68a202a0fb987a0325193508f64fee64f9f2eaa237bd55cd8fd0c2b86b6e8e4dbddd8fb3828a647570a86507e9adc32c7592b14e8d5eb76bd
7
+ data.tar.gz: abc0c95a41cfb1ccfb162025c408a092375d07188a3fa15204bfa556022f55ebcf4ddcefcb99a2128d95760006e913ae3544cba960b0470d4b0ebec7954ddada
@@ -1,3 +1,3 @@
1
1
  module Clearwater
2
- VERSION = "1.0.0.rc2"
2
+ VERSION = "1.0.0.rc3"
3
3
  end
@@ -4,21 +4,16 @@ module Clearwater
4
4
  module CachedRender
5
5
  def self.included base
6
6
  %x{
7
- Opal.defn(self, 'type', 'Thunk');
8
- Opal.defn(self, 'render', function(prev) {
9
- var self = this;
10
-
11
- if(prev && prev.vnode && #{!should_render?(`prev`)}) {
12
- return prev.vnode;
13
- } else {
14
- return #{Component.sanitize_content(render)};
15
- }
16
- });
7
+ Opal.defn(self, '$$cached_render', true);
17
8
  }
18
9
  end
19
10
 
20
11
  def should_render? _
21
12
  false
22
13
  end
14
+
15
+ def key
16
+ `undefined`
17
+ end
23
18
  end
24
19
  end
@@ -0,0 +1,32 @@
1
+ module Clearwater
2
+ module CachedRender
3
+ class Wrapper
4
+ attr_reader :content
5
+
6
+ def initialize content
7
+ @content = content
8
+ @key = content.key
9
+ end
10
+
11
+ # Hook into vdom diff/patch
12
+ %x{
13
+ def.type = 'Thunk';
14
+ def.render = function cached_render(prev) {
15
+ var self = this;
16
+
17
+ if(prev && prev.vnode && #{!@content.should_render?(`prev.content`)}) {
18
+ return prev.vnode;
19
+ } else {
20
+ var content = #{Component.sanitize_content(@content.render)};
21
+
22
+ while(content && content.type == 'Thunk' && content.render) {
23
+ content = #{Component.sanitize_content(`content.render(prev)`)};
24
+ }
25
+
26
+ return content;
27
+ }
28
+ };
29
+ }
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,6 @@
1
1
  require 'clearwater/virtual_dom'
2
2
  require 'clearwater/component/html_tags'
3
+ require 'clearwater/cached_render/wrapper'
3
4
 
4
5
  module Clearwater
5
6
  module Component
@@ -34,6 +35,12 @@ module Clearwater
34
35
  attributes
35
36
  end
36
37
 
38
+ # Runtime constant lookup isn't free, so if we cache a reference to it we
39
+ # don't have to do it every time we need to sanitize a node's content.
40
+ # This does need to happen at the JS level, though. If we use a Ruby
41
+ # variable, we won't have access to it in the method.
42
+ %x{ var wrapper = #{CachedRender::Wrapper}; }
43
+
37
44
  def self.sanitize_content content
38
45
  %x{
39
46
  if(content && content.$$class) {
@@ -42,10 +49,10 @@ module Clearwater
42
49
  } else {
43
50
  var render = content.$render;
44
51
 
45
- if(content.type === 'Thunk' && typeof(content.render) === 'function') {
46
- return content;
52
+ if(content.$$cached_render) {
53
+ return #{`wrapper`.new(content)};
47
54
  } else if(render && !render.$$stub) {
48
- return self.$sanitize_content(content.$render());
55
+ return #{sanitize_content(content.render)};
49
56
  } else {
50
57
  return content;
51
58
  }
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.rc2
4
+ version: 1.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Gaskins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-09 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -128,6 +128,7 @@ files:
128
128
  - opal/clearwater/application_registry.rb
129
129
  - opal/clearwater/black_box_node.rb
130
130
  - opal/clearwater/cached_render.rb
131
+ - opal/clearwater/cached_render/wrapper.rb
131
132
  - opal/clearwater/component.rb
132
133
  - opal/clearwater/dom_reference.rb
133
134
  - opal/clearwater/link.rb
@@ -142,7 +143,7 @@ files:
142
143
  - spec/clearwater/component_spec.rb
143
144
  - spec/clearwater/dom_reference_spec.rb
144
145
  - spec/spec_helper.rb
145
- homepage: https://clearwater-rb.github.io/
146
+ homepage: https://github.com/clearwater-rb/clearwater
146
147
  licenses:
147
148
  - MIT
148
149
  metadata: {}