Skip to content

Commit 2d15be1

Browse files
committed
closes #166 #165 #164 #160
1 parent caf88d1 commit 2d15be1

File tree

11 files changed

+80
-40
lines changed

11 files changed

+80
-40
lines changed

ruby/examples/misc/stock-tickers/.ruby-version

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

ruby/examples/misc/stock-tickers/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'https://rubygems.org'
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

4-
ruby '2.4.1'
4+
#ruby '2.4.1'
55

66
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
77
gem 'rails', '~> 5.2.1'

ruby/examples/misc/stock-tickers/Gemfile.lock

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PATH
22
remote: ../../../hyper-component
33
specs:
4-
hyper-component (1.0.alpha1.3)
5-
hyper-state (= 1.0.alpha1.3)
6-
hyperstack-config (= 1.0.alpha1.3)
4+
hyper-component (1.0.alpha1.4)
5+
hyper-state (= 1.0.alpha1.4)
6+
hyperstack-config (= 1.0.alpha1.4)
77
libv8 (~> 6.7.0)
88
mini_racer (~> 0.2.4)
99
opal (>= 0.11.0, < 0.12.0)
@@ -13,7 +13,7 @@ PATH
1313
PATH
1414
remote: ../../../hyper-spec
1515
specs:
16-
hyper-spec (1.0.alpha1.3)
16+
hyper-spec (1.0.alpha1.4)
1717
capybara
1818
chromedriver-helper (= 1.2.0)
1919
libv8
@@ -26,26 +26,26 @@ PATH
2626
selenium-webdriver
2727
timecop (~> 0.8.1)
2828
uglifier
29-
unparser (>= 0.2, < 0.4)
29+
unparser (>= 0.4.2)
3030
webdrivers
3131

3232
PATH
3333
remote: ../../../hyper-state
3434
specs:
35-
hyper-state (1.0.alpha1.3)
36-
hyperstack-config (= 1.0.alpha1.3)
35+
hyper-state (1.0.alpha1.4)
36+
hyperstack-config (= 1.0.alpha1.4)
3737
opal (>= 0.11.0, < 0.12.0)
3838

3939
PATH
4040
remote: ../../../hyper-trace
4141
specs:
42-
hyper-trace (1.0.alpha1.3)
43-
hyperstack-config (= 1.0.alpha1.3)
42+
hyper-trace (1.0.alpha1.4)
43+
hyperstack-config (= 1.0.alpha1.4)
4444

4545
PATH
4646
remote: ../../../hyperstack-config
4747
specs:
48-
hyperstack-config (1.0.alpha1.3)
48+
hyperstack-config (1.0.alpha1.4)
4949
listen (~> 3.0)
5050
mini_racer (~> 0.2.4)
5151
opal (>= 0.11.0, < 0.12.0)
@@ -164,7 +164,7 @@ GEM
164164
rails-dom-testing (>= 1, < 3)
165165
railties (>= 4.2.0)
166166
thor (>= 0.14, < 2.0)
167-
libv8 (6.7.288.46.1-x86_64-darwin-15)
167+
libv8 (6.7.288.46.1)
168168
listen (3.1.5)
169169
rb-fsevent (~> 0.9, >= 0.9.4)
170170
rb-inotify (~> 0.9, >= 0.9.7)
@@ -324,7 +324,7 @@ GEM
324324
thread_safe (~> 0.1)
325325
uglifier (4.1.19)
326326
execjs (>= 0.3.0, < 3)
327-
unparser (0.2.8)
327+
unparser (0.4.2)
328328
abstract_type (~> 0.0.7)
329329
adamantium (~> 0.2.0)
330330
concord (~> 0.1.5)
@@ -337,7 +337,7 @@ GEM
337337
activemodel (>= 5.0)
338338
bindex (>= 0.4.0)
339339
railties (>= 5.0)
340-
webdrivers (3.6.0)
340+
webdrivers (3.7.2)
341341
net_http_ssl_fix
342342
nokogiri (~> 1.6)
343343
rubyzip (~> 1.0)
@@ -383,8 +383,5 @@ DEPENDENCIES
383383
uglifier (>= 1.3.0)
384384
web-console (>= 3.3.0)
385385

386-
RUBY VERSION
387-
ruby 2.4.1p111
388-
389386
BUNDLED WITH
390387
2.0.1

ruby/examples/misc/stock-tickers/app/hyperstack/components/app.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class App < HyperComponent
88

99
before_mount { @symbols = Set.new }
1010

11-
def add_symbol
12-
mutate @symbols << @_symbol_input.value.upcase
13-
@_symbol_input.value = ''
11+
mutator :add_symbol do
12+
@symbols << jQ[@symbol_input].value.upcase
13+
jQ[@symbol_input].value = ''
1414
end
1515

1616
render do
@@ -22,7 +22,7 @@ def add_symbol
2222
BS::Row(style: { marginTop: 20 }) do
2323
BS::Col(sm: 4) do
2424
BS::InputGroup(class: 'mb-3') do
25-
BS::FormControl(ref: set_jq(:_symbol_input), placeholder: 'New Stock Market Symbol')
25+
@symbol_input = BS::FormControl(placeholder: 'New Stock Market Symbol')
2626
.on(:enter) { add_symbol }
2727
BS::InputGroup::Append() { BS::Button() { 'Add' } }
2828
.on(:click) { add_symbol }

ruby/examples/misc/stock-tickers/app/views/layouts/application.html.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949

5050
<body>
5151
<%= yield %>
52-
<script src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.js" crossorigin></script>
53-
54-
52+
<script src="https://unpkg.com/[email protected]/dist/react-bootstrap.js" crossorigin></script>
5553
</body>
5654
</html>

ruby/hyper-component/lib/hyperstack/component/element.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@ def _update_ref(x)
3939
end
4040

4141
def ref
42-
@ref || raise("#{self} has not been mounted yet")
42+
return @ref if @ref
43+
raise("The instance of #{self.type} has not been mounted yet") if properties[:ref]
44+
raise("Attempt to get a ref on #{self.type} which is a static component.")
4345
end
4446

4547
def dom_node
46-
@type.is_a?(String) ? ref : ref.dom_node
48+
`typeof #{ref}.$dom_node == 'function'` ? ref.dom_node : ref
4749
end
4850

49-
# Attach event handlers.
51+
# Attach event handlers. skip false, nil and blank event names
5052

5153
def on(*event_names, &block)
52-
event_names.each { |event_name| merge_event_prop!(event_name, &block) }
53-
@native = `React.cloneElement(#{@native}, #{@properties.shallow_to_n})`
54+
any_found = false
55+
event_names.each do |event_name|
56+
next unless event_name && event_name.strip != ''
57+
merge_event_prop!(event_name, &block)
58+
any_found = true
59+
end
60+
@native = `React.cloneElement(#{@native}, #{@properties.shallow_to_n})` if any_found
5461
self
5562
end
5663

ruby/hyper-component/lib/hyperstack/ext/component/element.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
Element.instance_eval do
22
def self.find(selector)
3-
selector = begin
4-
selector.dom_node
5-
rescue
6-
selector
7-
end if `#{selector}.$dom_node !== undefined`
3+
# the following rescue should no longer be needed,
4+
# and it prevents bubbling up necessary error messages
5+
# for improper use of refs.
6+
7+
# selector = begin
8+
# selector.dom_node
9+
# rescue
10+
# selector
11+
# end if `#{selector}.$dom_node !== undefined`
12+
13+
selector = selector.dom_node if `#{selector}.$dom_node !== undefined`
814
`$(#{selector})`
915
end
1016

ruby/hyper-component/spec/client_features/element_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
end
1919

2020
describe "Event Subscription" do
21-
it "keeps the original params" do
21+
it "keeps the original params, and ignores false, nil, and blank event names" do
2222
client_option render_on: :both
2323
mount 'Foo' do
2424
class Foo
2525
include Hyperstack::Component
2626
render do
27-
INPUT(value: nil, type: 'text').on(:change) {}
27+
INPUT(value: nil, type: 'text').on(:change, false, nil, " ") {}
2828
end
2929
end
3030
end

ruby/hyper-component/spec/client_features/refs_element_method_spec.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AnotherComponent < HyperComponent
3434
render(DIV) { "another component"}
3535
end
3636
class TestComponent < HyperComponent
37-
after_mount { raise "Failed" unless jQ[@another_component].html == 'another component' }
37+
after_mount { raise 'Failure' unless jQ[@another_component].html == 'another component' }
3838
render do
3939
@another_component = AnotherComponent()
4040
end
@@ -43,14 +43,40 @@ class TestComponent < HyperComponent
4343
expect(page).to have_content('another component')
4444
end
4545

46+
it "the ref method has a dom_node method that works with native react components" do
47+
mount 'TestComponent' do
48+
JS.call(:eval,
49+
<<-JSCODE
50+
window.NativeComponent = class extends React.Component {
51+
constructor(props) {
52+
super(props);
53+
this.displayName = "aNativeComponent";
54+
}
55+
render() { return React.createElement("div", null, "a native component"); }
56+
}
57+
JSCODE
58+
)
59+
class AnotherComponent < Hyperloop::Component
60+
imports "NativeComponent"
61+
end
62+
class TestComponent < HyperComponent
63+
after_mount { raise 'Failure' unless jQ[@another_component].html == 'a native component' }
64+
render do
65+
@another_component = AnotherComponent()
66+
end
67+
end
68+
end
69+
expect(page).to have_content('a native component')
70+
end
71+
4672
it 'the ref method has a dom_node method that works with application components' do
4773
mount 'TestComponent' do
4874
class AnotherComponent < HyperComponent
4975
other :others
5076
render(DIV) { "another component named #{@Others[:foo]}"}
5177
end
5278
class TestComponent < HyperComponent
53-
after_mount { raise "Failed" unless @ref_1.ref == @ref_2.ref }
79+
after_mount { debugger unless @ref_1.ref == @ref_2.ref; nil }
5480
render do
5581
@ref_1 = AnotherComponent().as_node
5682
@ref_2 = @ref_1.render(foo: :bar)

ruby/hyper-model/lib/active_record_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def has_many(name, *args, &block)
255255
pre_syncromesh_has_many name, *args, opts.except(:regulate), &block
256256
end
257257

258-
%i[belongs_to has_one].each do |macro|
258+
%i[belongs_to has_one composed_of].each do |macro|
259259
alias_method :"pre_syncromesh_#{macro}", macro
260260
define_method(macro) do |name, *aargs, &block|
261261
define_method(:"__secure_remote_access_to_#{name}") do |this, _acting_user, *args|

0 commit comments

Comments
 (0)