opal-virtual-dom 0.1.0 → 0.2.0

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: 8f0189e3d7be5aca3994abaae718dc232650dfa5
4
- data.tar.gz: 0ea3804fb5020f857b5d0d51e59e570ffa8fd99b
3
+ metadata.gz: 401a70f8753aef7fce8a51c5ab95b3465a042685
4
+ data.tar.gz: 3a9a07a08771f8396e1bef15f6b1fa91e282e3a0
5
5
  SHA512:
6
- metadata.gz: 2d2e4b6e53f95b21bec2d55d302f6513e5e1b0055539f1283169632466616dc52bd947667dc16e13dc1d22754523e5892d3f846ebcd947b6b3ecd2769eed5b72
7
- data.tar.gz: 2b96075d013c8b42dae30f2135a6a1e4c016822b39b07c7c676ab24f0c0973941e920a7da9fc1480657958279d3dbbea06ad08b48b8079f1e540b12a8472adb1
6
+ metadata.gz: aad3c3671d1684e8877e7faaf9a6013babec2286f438c0ef03d23c08690a19117317c0e0ad7d51dcc0dbd82821c125f2331ce1381f2849513c53db4ed94ffc5d
7
+ data.tar.gz: 44a3b43d32e3f4ee82e575bd7d8990e4a846db382a6d0a0b97ba5863ec1d126f2e6536ae5d861ea28bef8d1e7eaf68688d99f4e7e022eb2f3f9060e7792fa67e
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opal-virtual-dom'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.authors = [ 'Michał Kalbarczyk' ]
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/fazibear/opal-virtual-dom'
@@ -15,36 +15,34 @@ module VirtualDOM
15
15
  if block
16
16
  current = @__virtual_nodes__
17
17
  @__virtual_nodes__ = []
18
- result = block.call
19
- vnode = VirtualNode.new(tag, process_params(params), @__virtual_nodes__.count == 0 ? result : @__virtual_nodes__).vnode
18
+ result = block.call || ''
19
+ vnode = VirtualNode.new(tag, process_params(params), @__virtual_nodes__.count == 0 ? result : @__virtual_nodes__).to_n
20
20
  @__virtual_nodes__ = current
21
21
  else
22
- vnode = VirtualNode.new(tag, process_params(params), []).vnode
22
+ vnode = VirtualNode.new(tag, process_params(params), []).to_n
23
23
  end
24
24
  @__virtual_nodes__ << vnode
25
25
  vnode
26
26
  end
27
27
  end
28
28
 
29
- def text(string)
30
- @__virtual_nodes__ << VirtualTextNode.new(string).vnode
31
- end
32
-
33
29
  def process_params(params)
34
- if params && params.is_a?(Hash)
35
- params.each do |k, v|
36
- case k
37
- when 'class'
38
- params['className'] = params.delete('class')
39
- when /^on/
40
- params[k] = ->(e) { v.call(Native(e)) }
41
- end
30
+ return {} unless params.is_a?(Hash)
31
+ params.each do |k, v|
32
+ case k
33
+ when 'class'
34
+ params['className'] = params.delete('class')
35
+ when /^on/
36
+ params[k] = ->(e) { v.call(Native(e)) }
42
37
  end
43
- else
44
- {}
45
38
  end
46
39
  end
47
40
 
41
+ # for backwards compatibility, you can return string
42
+ def text(string)
43
+ @__virtual_nodes__ << string.to_s
44
+ end
45
+
48
46
  # for backwards compatibility
49
47
  def virtual_dom(&block)
50
48
  block.call
@@ -6,7 +6,7 @@ module VirtualDOM
6
6
  @childrens = childrens
7
7
  end
8
8
 
9
- def vnode
9
+ def to_n
10
10
  `virtualDom.h(#{@name}, #{@params.to_n}, #{@childrens})`
11
11
  end
12
12
 
@@ -15,11 +15,10 @@ module VirtualDOM
15
15
  end
16
16
 
17
17
  def to_s_params
18
- if @params.any?
19
- " " + @params.map do |k,v|
20
- "#{k}=\"#{v}\""
21
- end.join(' ')
22
- end
18
+ return unless @params.any?
19
+ ' ' + @params.map do |k, v|
20
+ "#{k}=\"#{v}\""
21
+ end.join(' ')
23
22
  end
24
23
  end
25
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-virtual-dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Kalbarczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -53,7 +53,6 @@ files:
53
53
  - opal/virtual_dom.rb
54
54
  - opal/virtual_dom/dom.rb
55
55
  - opal/virtual_dom/virtual_node.rb
56
- - opal/virtual_dom/virtual_text_node.rb
57
56
  - opal/virtual_dom/wrapper.rb
58
57
  homepage: http://github.com/fazibear/opal-virtual-dom
59
58
  licenses: []
@@ -1,15 +0,0 @@
1
- module VirtualDOM
2
- class VirtualTextNode
3
- def initialize(text)
4
- @text = text
5
- end
6
-
7
- def vnode
8
- @text.to_s
9
- end
10
-
11
- def to_s
12
- @text
13
- end
14
- end
15
- end