This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-4
lines changed
Expand file tree Collapse file tree 2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,16 @@ def []=(state, new_value)
1515
1616 def method_missing ( method , *args )
1717 if match = method . match ( /^(.+)\! $/ )
18+ key_name = $1
1819 if args . count > 0
1920 current_value = State . get_state ( @from , match [ 1 ] )
20- State . set_state ( @from , $1 , args [ 0 ] )
21+ State . set_state ( @from , key_name , args [ 0 ] )
2122 current_value
2223 else
2324 current_state = State . get_state ( @from , match [ 1 ] )
24- State . set_state ( @from , $1 , current_state )
25+ State . set_state ( @from , key_name , current_state )
2526 Observable . new ( current_state ) do |update |
26- State . set_state ( @from , $1 , update )
27+ State . set_state ( @from , key_name , update )
2728 end
2829 end
2930 else
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
33if opal?
4+
45describe 'React::Observable' do
5- # tbd
6+ it "allows to set value on Observable" do
7+ stub_const 'Zoo' , Class . new {
8+ include React ::Component
9+ param :foo , type : React ::Observable
10+ before_mount do
11+ params . foo! 4
12+ end
13+
14+ def render
15+ nil
16+ end
17+ }
18+
19+ stub_const 'Foo' , Class . new
20+ Foo . class_eval do
21+ include React ::Component
22+
23+ def render
24+ div do
25+ Zoo ( foo : state . foo! )
26+ span { state . foo . to_s }
27+ end
28+ end
29+ end
30+
31+ instance = React ::Test ::Utils . render_into_document ( React . create_element ( Foo ) )
32+ html = `#{ instance . dom_node } .innerHTML`
33+ # data-reactid appear in earlier versions of reactjs
34+ %x{
35+ var REGEX_REMOVE_IDS = /\s ?data-reactid="[^"]+"/g;
36+ html = html.replace(REGEX_REMOVE_IDS, '');
37+ }
38+ expect ( html ) . to eq ( '<span></span><span>4</span>' )
39+ end
640end
41+
742end
You can’t perform that action at this time.
0 commit comments