Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 3cdc9e2

Browse files
committed
not working but
1 parent a9c7369 commit 3cdc9e2

File tree

12 files changed

+75
-48
lines changed

12 files changed

+75
-48
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
source 'https://rubygems.org'
22

3+
gem 'hyper-react', path: '../hyper-react'
4+
5+
36
# Specify your gem's dependencies in hyper-store.gemspec
47
gemspec

Gemfile.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
PATH
2+
remote: ../hyper-react
3+
specs:
4+
hyper-react (0.11.0)
5+
hyper-store
6+
opal (>= 0.8.0)
7+
opal-activesupport (>= 0.2.0)
8+
react-rails
9+
110
PATH
211
remote: .
312
specs:
@@ -82,10 +91,6 @@ GEM
8291
globalid (0.3.7)
8392
activesupport (>= 4.1.0)
8493
hike (1.2.3)
85-
hyper-react (0.11.0)
86-
opal (>= 0.8.0)
87-
opal-activesupport (>= 0.2.0)
88-
react-rails
8994
hyper-spec (0.1.0)
9095
capybara
9196
opal
@@ -273,7 +278,7 @@ PLATFORMS
273278

274279
DEPENDENCIES
275280
bundler (~> 1.12)
276-
hyper-react (>= 0.10.0)
281+
hyper-react!
277282
hyper-spec
278283
hyper-store!
279284
listen

lib/hyper-store.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'hyper-react'
2-
31
require 'hyper-store/class_methods'
42
require 'hyper-store/dispatch_receiver'
53
require 'hyper-store/instance_methods'
@@ -9,7 +7,10 @@
97
require 'hyper-store/version'
108
require 'hyperloop/store'
119
require 'hyperloop/store/mixin'
10+
require 'react/state'
1211

1312
if RUBY_ENGINE != 'opal'
13+
require 'opal'
14+
1415
Opal.append_path(File.expand_path('../', __FILE__).untaint)
1516
end

lib/hyper-store/instance_methods.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module HyperStore
22
module InstanceMethods
3-
def initialize
3+
def init_store
44
self.class.__instance_states.each do |instance_state|
55
# If the scope is shared then we initialize at the class level
66
next if instance_state[1][:scope] == :shared
@@ -19,7 +19,6 @@ def initialize
1919
mutate.send(:"#{instance_state[0]}", block_value)
2020
end
2121

22-
super
2322
end
2423

2524
def state

lib/hyper-store/mutator_wrapper.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module HyperStore
2-
class MutatorWrapper
3-
attr_reader :from
2+
class MutatorWrapper < BasicObject
43

54
class << self
65
def add_method(klass, method_name, opts = {})
76
define_method(:"#{method_name}") do |*args|
8-
from = opts[:scope] == :shared ? klass.state.from : @from
7+
from = opts[:scope] == :shared ? klass.state.__from__ : @__from__
98
current_value = React::State.get_state(from, method_name.to_s)
109

1110
if args.count > 0
@@ -55,14 +54,22 @@ def initializer_proc(initializer, klass, name)
5554
end
5655
end
5756

58-
def initialize(from)
59-
@from = from
57+
attr_accessor :__from__
58+
59+
def self.new(from)
60+
instance = allocate
61+
instance.__from__ = from
62+
instance
63+
end
64+
65+
def __class__
66+
(class << self; self end).superclass
6067
end
6168

6269
# Any method_missing call will create a state and accessor with that name
6370
def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissing
64-
self.class.add_method(nil, name)
65-
send(name, *args, &block)
71+
__class__.add_method(nil, name)
72+
__send__(name, *args, &block)
6673
end
6774
end
6875
end

lib/hyper-store/state_wrapper.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module HyperStore
2-
class StateWrapper
2+
class StateWrapper #< BasicObject # TODO StateWrapper should from basic object to avoid name space conflicts
33
extend ArgumentValidator
44

5-
attr_reader :from
6-
75
class << self
86
attr_reader :instance_state_wrapper, :class_state_wrapper,
97
:instance_mutator_wrapper, :class_mutator_wrapper,
@@ -69,7 +67,7 @@ def add_methods(klass, name, opts)
6967

7068
def add_method(klass, method_name, opts = {})
7169
define_method(:"#{method_name}") do
72-
from = opts[:scope] == :shared ? klass.state.from : @from
70+
from = opts[:scope] == :shared ? klass.state.__from__ : @__from__
7371
React::State.get_state(from, method_name.to_s)
7472
end
7573
end
@@ -91,13 +89,20 @@ def default_scope(klass)
9189
end
9290
end
9391

92+
attr_accessor :__from__
93+
9494
def initialize(from)
95-
@from = from
95+
__from__ = from
9696
end
9797

98+
# def self.new(from)
99+
# instance = allocate
100+
# instance.__from__ = from
101+
# instance
102+
# end
98103
# Any method_missing call will create a state and accessor with that name
99104
def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissing
100-
self.class.add_method(nil, name)
105+
self.class.add_method(nil, name) #(class << self; self end).superclass.add_method(nil, name)
101106
send(name, *args, &block)
102107
end
103108
end

lib/hyper-store/state_wrapper/argument_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module HyperStore
2-
class StateWrapper
2+
class StateWrapper < BasicObject
33
module ArgumentValidator
44
class InvalidOptionError < StandardError; end
55

lib/hyperloop/store.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ def inherited(child)
55
child.include(Mixin)
66
end
77
end
8+
def initialize
9+
init_store
10+
end
811
end
912
end

spec/test_app/.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/test_app/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gem 'sqlite3'
1111
gem 'puma', '~> 3.6.0'
1212
gem 'jquery-rails'
1313

14-
gem 'hyper-react'
14+
gem 'hyper-react', path: '../../../hyper-react'
1515
gem 'hyper-spec', git: 'https://www.github.com/ruby-hyperloop/hyper-spec'
1616
gem 'hyper-store', path: '../..'
1717
gem 'opal', '~> 0.9.0'

0 commit comments

Comments
 (0)