rwr-react_router 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7b462334865192fbb07b80e8621277f714c2288
4
- data.tar.gz: 43242f975b90f04020d90dcec54c89b1e5a8c416
3
+ metadata.gz: 1a3833f3d96ddf37b3fbb317b63d5792732242f3
4
+ data.tar.gz: cb17d557a4919ff1f8af7922287e84b327577cb3
5
5
  SHA512:
6
- metadata.gz: ee235dca96f5b32928e23f6aeb0145a9d6728cb1749a26094aff66a29cd9004e921dcbe4afbab45ba3bd817b13a17cdb8a8503c88a3f196ba5c6bc07a1fead0d
7
- data.tar.gz: 00a6283039ef9f1ec8802a465b7e1b4a9116750615241d08d8f1ba33ef0eae8b1f07238390c053a84e38a0b82adf3b02838384af8b871c27cf51b4a9fb9431cb
6
+ metadata.gz: af6cc16e5dab4b9bfe781b7538ad14aab6896b0efcf37663447d5abd969406ee6b8d5090326bc7df8b33c6ce2175cd178f5095a86b617ce1eae8c82b6e91f07d
7
+ data.tar.gz: 3326daef28a1425b97d67178dfb947139d7ef39e6dc92ba36d41baf70af7f21e92c58c66b7501fd56098cc3820a8d79eda3d90c0ef2186dbb0cecd1fcf3f09eb
data/.travis.yml CHANGED
@@ -7,7 +7,8 @@ language: ruby
7
7
  cache:
8
8
  bundler: true
9
9
  directories:
10
- - node_modules
10
+ - node_modules
11
+ - spec/rails4_dummy_app/node_modules
11
12
 
12
13
  matrix:
13
14
  include:
data/CHANGELOG.md CHANGED
@@ -1 +1,6 @@
1
- ## UNRELEASED
1
+ ## 0.2.0 21 March 2016
2
+ * support passing props to router.
3
+
4
+ ## 0.1.0 Initial release
5
+ * `react_router` view helper for rendering router in rails view.
6
+ * `rwr-react-router` npm package
data/README.md CHANGED
@@ -34,6 +34,24 @@ RWRReactRouter.register('MyRouter', MyRouter);
34
34
  <%= react_router('MyRouter') %>
35
35
  ```
36
36
 
37
+ ### Passing props to router.
38
+ `RWRReactRouter.register` accepts both - react-router instance and function.
39
+ When registering function instead of react-router instance, integration will take props (if any were passed to `react_router` helper) and will pass them to given function as first argument. This way you can pass them down to router of you choice:
40
+ ```js
41
+ function RouterWithProps(props) {
42
+ return (
43
+ <Router history={browserHistory}>
44
+ <Route path="/with_props" component={App} yourName={props}>
45
+ <Route path="about" component={About}/>
46
+ <Route path="home" component={Home}/>
47
+ </Route>
48
+ </Router>
49
+ );
50
+ }
51
+ ```
52
+
53
+ Props passed to route will be available under `props.route.yourName`.
54
+
37
55
  ## Contributing
38
56
  ## Issues
39
57
 
data/Rakefile CHANGED
@@ -44,6 +44,6 @@ namespace :setup do
44
44
 
45
45
  desc 'Prepare rails4 test app dependencies'
46
46
  task :rails4 do
47
- sh %Q(npm install && cd spec/rails4_dummy_app && npm install && bundle install)
47
+ sh %Q(npm install && cd spec/rails4_dummy_app && rm -rf node_modules/rwr-react-router && npm install && bundle install)
48
48
  end
49
49
  end
data/js/src/index.js CHANGED
@@ -19,7 +19,7 @@ class ReactRouterIntegration {
19
19
  return this.routers[name];
20
20
  }
21
21
 
22
- render(name, node) {
22
+ render(name, node, props = {}) {
23
23
  if (this.enabled === true) {
24
24
  throw new Error(
25
25
  `Error when rendering ${name}\n
@@ -27,7 +27,9 @@ class ReactRouterIntegration {
27
27
  );
28
28
  }
29
29
  this.enabled = true;
30
- ReactDOM.render(this.get(name), node);
30
+ const constructor = this.get(name);
31
+ const router = typeof(constructor) === 'function' ? constructor(props) : constructor;
32
+ ReactDOM.render(router, node);
31
33
  }
32
34
 
33
35
  unmount(node) {
@@ -38,7 +40,7 @@ class ReactRouterIntegration {
38
40
  get integrationWrapper() {
39
41
  return {
40
42
  mount: function _mount(node, payload) {
41
- this.render(payload.name, node);
43
+ this.render(payload.name, node, payload.props);
42
44
  }.bind(this),
43
45
 
44
46
  unmount: function _unmount(node) {
data/js/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.1.0';
1
+ export default '0.2.0';
data/js/test/index.js CHANGED
@@ -115,13 +115,14 @@ describe('RWRReactRouter', function () {
115
115
  it('calls renderComponent', function () {
116
116
  const mountSpy = spyOn(subject, 'render');
117
117
 
118
- const payload = { name: 'routerName' };
118
+ const payload = { name: 'routerName', props: { foo: 'bar' } };
119
119
  subject.integrationWrapper.mount(node, payload);
120
120
 
121
121
  expect(mountSpy.calls.length).toEqual(1);
122
122
  expect(mountSpy).toHaveBeenCalledWith(
123
123
  'routerName',
124
- { nodeType: 1, nodeName: 'DIV' }
124
+ { nodeType: 1, nodeName: 'DIV' },
125
+ { foo: 'bar' }
125
126
  );
126
127
  });
127
128
  });
@@ -1,5 +1,5 @@
1
1
  module ReactWebpackRails
2
2
  module ReactRouterIntegration
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -1,8 +1,8 @@
1
1
  module ReactWebpackRails
2
2
  module ReactRouterIntegration
3
3
  module ViewHelpers
4
- def react_router(name)
5
- react_element('react-router', name: name)
4
+ def react_router(name, props = {})
5
+ react_element('react-router', name: name, props: props)
6
6
  end
7
7
  end
8
8
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwr-react-router",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "js/lib/index.js",
6
6
  "files": [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwr-react_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Gawlik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-20 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler