hyalite 0.0.2 → 0.0.3

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: ad8c51336a33fc4b94adf83702f0c24611551752
4
- data.tar.gz: 55032da2177b4efbdf791a7866e6bafea0fe0d90
3
+ metadata.gz: 1ea1c7240e460e33ee5ebfc1e434cd7493198c45
4
+ data.tar.gz: c5f2098f1cfad4a794930c88f3adca4b0e6d15fe
5
5
  SHA512:
6
- metadata.gz: 2ea894199b0519cab7c4b75c5b399a81f4d1cd21aa8aaa8b9d8c594870a42e11fc1e8a2e09dbe124e12af46000858a9398287fb284c2bedcbbd51428dfa33809
7
- data.tar.gz: 1e017dd83054e9b768a47144b4b350534d3b029668169caae99da33011a5ec8558473bc75b73ac79a28476fa54681d13d0df6251ced2e184840cc682942397ae
6
+ metadata.gz: 2cbdd7ea485e11cd21a38a898b3f6287e122d5e55664ccc5843672a8e7c7c897b7842e96991f673b20ce334a37f15f3106d427e1d1fa311ed34dfd677711acc8
7
+ data.tar.gz: b62902c084737bc896fc51690a8ee60ca7b819b6946741643e255ed2abf37733f1fd7fe078600d64bb5f82bca663ab719a254e3751bbf425cc34eece7b7f28e3
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hyalite (0.0.2)
4
+ hyalite (0.0.3)
5
5
  opal
6
6
  opal-browser
7
7
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Hyalite
2
2
  ====
3
3
 
4
+ [![Build Status](https://travis-ci.org/youchan/hyalite.svg?branch=master)](https://travis-ci.org/youchan/hyalite)
5
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/youchan/hyalite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
6
+
7
+
4
8
  This is ruby virtual DOM implementation using opal. It is inspired by react.js.
5
9
 
6
10
  Example
@@ -3,18 +3,36 @@ require 'hyalite/short_hand'
3
3
  module Hyalite
4
4
  module Component
5
5
 
6
- attr_accessor :props, :state, :context, :refs
6
+ attr_accessor :props, :context, :refs
7
7
 
8
8
  def init_component(props, context, updator)
9
9
  @props = props
10
10
  @context = context
11
11
  @updator = updator
12
- @state = initial_state
12
+ @state = State.new(self, updator, initial_state)
13
13
  @refs = nil
14
14
  end
15
15
 
16
+ def self.included(clazz)
17
+ clazz.instance_eval do
18
+ define_singleton_method(:state) do |key, initial_value|
19
+ (@initial_state ||= {})[key] = initial_value
20
+ end
21
+
22
+ define_singleton_method(:initial_state) { @initial_state || {} }
23
+ end
24
+ end
25
+
16
26
  def initial_state
17
- {}
27
+ self.class.initial_state
28
+ end
29
+
30
+ def state
31
+ @state.to_h
32
+ end
33
+
34
+ def state=(state)
35
+ @state.set(state)
18
36
  end
19
37
 
20
38
  def context_types
@@ -63,6 +81,34 @@ module Hyalite
63
81
 
64
82
  def render
65
83
  end
84
+
85
+ class State
86
+ def initialize(component, updator, initial_state)
87
+ @component = component
88
+ @updator = updator
89
+ @state = initial_state.clone
90
+ initial_state.each do |key, value|
91
+ define_singleton_method(key) do
92
+ @state[key]
93
+ end
94
+ define_singleton_method(key + '=') do |value|
95
+ @updator.enqueue_set_state(@component, key => value)
96
+ end
97
+ end
98
+ end
99
+
100
+ def [](key)
101
+ @state[key]
102
+ end
103
+
104
+ def set(state)
105
+ @state = state.clone
106
+ end
107
+
108
+ def to_h
109
+ @state
110
+ end
111
+ end
66
112
  end
67
113
 
68
114
  class EmptyComponent
@@ -1,3 +1,3 @@
1
1
  module Hyalite
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyalite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".gitignore"
76
77
  - ".travis.yml"
77
78
  - Gemfile
78
79
  - Gemfile.lock