reactive-router 0.7.2 → 0.7.2.1

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: de5d8d7aa19c159852f4e5722fb3e8e966906f97
4
- data.tar.gz: 3c899bf968c0a8159e1d9a54718abbd7003a2c41
3
+ metadata.gz: 4a1f60fd3c97f98310d7643481504e00b0e951b4
4
+ data.tar.gz: f718f2647d0ec852ed16bbb58d1380fd24cee429
5
5
  SHA512:
6
- metadata.gz: a33cc7159885f78d3440c7f313200f125854ed78e4b14eb8cc6456777acc12a7aaf48f4d8fc589f12607b92b2f90f3b5002e5a5ff2d00e8d5df4228838999e46
7
- data.tar.gz: aecb8065ccb425998f6e0efd331e6e5795645aef666b1e0102d52646681e3d8376a0a0372022282916a91dbe98ef0f42625872217d9fcd0a08b282760b7384d0
6
+ metadata.gz: 0cf192f6f4ac03fca07ea4d664beee3099e9001be8cbfb6ea6c3a8e330382260b292f2bb9c99902932df6e818a51e5e485965768bfd8cbda63d49cfe10ebac47
7
+ data.tar.gz: 69b2a639e7372c004b95ea30feb25ae5567fbf04d8e02662b15feb066d6627d1dd30b3afad6ef04fe39fa1c0f44708c2bebfa29d9633d862acb3fd869b2b9a70
data/README.md CHANGED
@@ -20,7 +20,150 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ The router is a React component that loads other components depending on the current URL.
24
+
25
+ Unlike other compnents there can only be one router on a page.
26
+
27
+ To get you started here is a sample router.
28
+
29
+ ```ruby
30
+ module Components
31
+ module Accounts
32
+
33
+ class Show
34
+
35
+ include React::Router # instead of React::Component, you use React::Router
36
+
37
+ # the routes macro creates the mapping between URLs and components to display
38
+
39
+ routes(path: "/account/:user_id") do # i.e. we expect to see something like /account/12345
40
+ # routes can be nested the dashboard will be at /account/12345/dashboard
41
+ # the DashboardRoute component will be mounted
42
+ route(name: "Dashboard", path: "dashboard", handler: Components::Accounts::DashboardRoute)
43
+ route(path: "orders", name: "Orders", handler: Components::Accounts::OrdersRoute)
44
+ # when displaying an order we need the order order as well as the user_id
45
+ route(path: "orders/:order_id", name: "Order", handler: Components::Accounts::OrderRoute)
46
+ route(path: "statement", name: "Statement", handler: Components::Accounts::StatementRoute)
47
+ # the special redirect route
48
+ redirect(from: "/account/:user_id", to: "Dashboard")
49
+ end
50
+
51
+ # you grab the url params and preprocess them using the router_param macro.
52
+ # when Router is mounted it will receive the :user_id from the url. In this case we grab
53
+ # the corresponding active_record model.
54
+
55
+ router_param :user_id do |id|
56
+ User.find(id)
57
+ end
58
+
59
+ # like any component routers can have params that are passed in when the router is mounted
60
+
61
+ required_param :user_param, type: User
62
+ required_param :user_orders_param, type: [Order]
63
+ required_param :production_center_address_param, type: Address
64
+ required_param :open_invoices_param
65
+ required_param :user_profiles_param, type: [PaymentProfile]
66
+ required_param :user_addresses_param, type: [Address]
67
+
68
+ # because the underlying javascript router has no provisions to pass params we
69
+ # will export states and copy the params to the states so the lower components can read them
70
+ # expect this get fixed in the near future
71
+
72
+ export_state :user
73
+ export_state :production_center_address
74
+ export_state :open_invoices
75
+ export_state :payment_profiles
76
+ export_state :addresses
77
+
78
+ # the router also makes a good place for other top level states to be housed (i.e. the flux architecture)
79
+ export_state :order_count
80
+
81
+ before_mount do
82
+ # before mounting the router we copy the incoming params that the lower level components will need
83
+ user! user_param
84
+ production_center_address! production_center_address_param
85
+ open_invoices! open_invoices_param
86
+ payment_profiles! user_profiles_param
87
+ addresses! user_addresses_param
88
+
89
+ order_count! user.orders.count # grab our top level state info and save it away
90
+
91
+ end
92
+
93
+ # For routers you define a show method instead of a render method
94
+ def show
95
+ div do
96
+ div.account_nav do
97
+
98
+ # link is a special router component that generates an on page link, that will maintain history etc.
99
+ # basically an intelligent anchor tag. When a user clicks a link, it will rerender the router, update
100
+ # the history etc.
101
+ # So for example when "My Statement" is clicked. The route changes to /account/:id/statement
102
+
103
+ link(to: "Dashboard", class: "no-underline btn btn-default", params: { user_id: user.id }) { "Account Dashboard" }
104
+ link(to: "Orders", class: "no-underline btn btn-default", params: { user_id: user.id }) { "My Quotes & Orders" }
105
+ link(to: "Statement", class: "no-underline btn btn-default", params: { user_id: user.id }) { "My Statement" }
106
+
107
+ end
108
+ # someplace in the router show method you will have route_handler component which mounts and renders the component
109
+ # indicated by the current route.
110
+ route_handler
111
+ end
112
+ end
113
+ end
114
+
115
+ # We can't pass parameters to the routed components, so we set up these mini components
116
+ # which grab the state from router and send it along to the actual component
117
+
118
+ class DashboardRoute
119
+
120
+ include React::Component
121
+
122
+ def render
123
+ AccountDashboard user: Show.user, addresses: Show.addresses, payment_profiles: Show.payment_profiles
124
+ end
125
+
126
+ end
127
+
128
+ class StatementRoute
129
+
130
+ include React::Component
131
+
132
+ def render
133
+ Statement production_center_address: Show.production_center_address,
134
+ open_invoices: Show.open_invoices, current_invoices: Show.open_invoices[:invoices],
135
+ mailing_address: Show.open_invoices[:mailing_address]
136
+ end
137
+
138
+ end
139
+
140
+ class OrdersRoute
141
+
142
+ include React::Component
143
+
144
+ def render
145
+ AccountOrders user: Show.user #, orders: Show.orders
146
+ end
147
+
148
+ end
149
+
150
+ class OrderRoute
151
+
152
+ include React::Component
153
+
154
+ router_param :order_id do |id|
155
+ Order.find(id)
156
+ end
157
+
158
+ def render
159
+ OrderShow(order: order_id, referrer: "account")
160
+ end
161
+
162
+ end
163
+
164
+ end
165
+ end
166
+ ```
24
167
 
25
168
  ## Development
26
169
 
@@ -1,3 +1,4 @@
1
+
1
2
  module React
2
3
 
3
4
  module Router
@@ -36,7 +37,7 @@ module React
36
37
  routes = self.class.build_routes
37
38
  %x{
38
39
  ReactRouter.run(#{routes}, window.reactive_router_static_location, function(root) {
39
- self.root = React.createElement(root);
40
+ self.root = React.createElement(root, self.native.props);
40
41
  });
41
42
  }
42
43
  React::Element.new(@root, 'Root', {}, nil)
@@ -55,11 +56,15 @@ module React
55
56
 
56
57
  after_mount do
57
58
  unless self.class.routing!
58
- dom_node = `React.findDOMNode(#{self}.native)`
59
+ dom_node = if `typeof React.findDOMNode === 'undefined'`
60
+ `#{self}.native.getDOMNode` # v0.12.0
61
+ else
62
+ `React.findDOMNode(#{self}.native)` # v0.13.0
63
+ end
59
64
  routes = self.class.build_routes
60
65
  %x{
61
66
  ReactRouter.run(#{routes}, ReactRouter.HistoryLocation, function(root) {
62
- React.render(React.createElement(root), #{dom_node});
67
+ React.render(React.createElement(root, self.native.props), #{dom_node});
63
68
  });
64
69
  }
65
70
  end
@@ -1,3 +1,3 @@
1
1
  module ReactiveRouter
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam George
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler