rwr-redux 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.babelrc +3 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +38 -0
- data/bin/console +14 -0
- data/bin/setup +5 -0
- data/js/.eslintrc +12 -0
- data/js/src/index.js +110 -0
- data/js/src/utils/validators.js +22 -0
- data/js/src/version.js +1 -0
- data/js/test/index.js +188 -0
- data/lib/react_webpack_rails/redux_integration/engine.rb +6 -0
- data/lib/react_webpack_rails/redux_integration/railtie.rb +11 -0
- data/lib/react_webpack_rails/redux_integration/version.rb +5 -0
- data/lib/react_webpack_rails/redux_integration/view_helpers.rb +22 -0
- data/lib/rwr-redux.rb +6 -0
- data/package.json +46 -0
- data/redux_integration.gemspec +30 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1630fa9a3b81dc6c3d2ec3c0addd9946d07a86a3
|
4
|
+
data.tar.gz: a05514f58e13b5c76d097ca240d81b60633b76a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d69c3e0d715fbcb0da13f9e4dab1af464743c2f5cf8ef5b28c923bc3df6c903954668a3c211b51741097f9bfa98f77587a76a8e4c9b9302fa2747c14c374c405
|
7
|
+
data.tar.gz: 59432c4ff71dc67989c25cd6109053631b43ea3fd686b8dc4ee1557d98707a35305fd826e00232713f1ba20069d0d04743fd468608208802fc455937881b1523
|
data/.babelrc
ADDED
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
## UNRELEASED
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Rafał Gawlik
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
rwr-redux
|
2
|
+
====
|
3
|
+
[Redux.js](http://redux.js.org/) integration plugin for [react_webpack_rails](https://github.com/netguru/react_webpack_rails).
|
4
|
+
|
5
|
+
This integration allows to use redux state containers in a diffrent part of rails views.
|
6
|
+
|
7
|
+
## Setup
|
8
|
+
* Add `rwr-redux` to your Gemfile:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem 'rwr-redux'
|
12
|
+
```
|
13
|
+
|
14
|
+
* Install rwr-redux package:
|
15
|
+
|
16
|
+
```
|
17
|
+
$ npm install --save rwr-redux
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### register store and components in react/index.js
|
23
|
+
|
24
|
+
Register store:
|
25
|
+
|
26
|
+
```js
|
27
|
+
import Store from './store';
|
28
|
+
RWRRedux.registerStore('MyStoreName', Store);
|
29
|
+
```
|
30
|
+
|
31
|
+
Register redux container:
|
32
|
+
|
33
|
+
```js
|
34
|
+
import Container from './containers/MyContainerName';
|
35
|
+
RWRRedux.registerContainer('MyContainerName', Container);
|
36
|
+
```
|
37
|
+
|
38
|
+
### use registered store and componetns in Rails view
|
39
|
+
|
40
|
+
Define store with initial state:
|
41
|
+
|
42
|
+
```erb
|
43
|
+
<%= redux_store 'MyStoreName', { foo: @bar } %>
|
44
|
+
```
|
45
|
+
|
46
|
+
Add Redux container:
|
47
|
+
|
48
|
+
```erb
|
49
|
+
<%= redux_container 'MyContainerName' %>
|
50
|
+
```
|
51
|
+
|
52
|
+
If you have more than one store in a view, you can specify `store_name`:
|
53
|
+
|
54
|
+
```erb
|
55
|
+
<%= redux_container 'MyContainerName', store_name: 'MyStoreName' %>
|
56
|
+
```
|
57
|
+
|
58
|
+
### using redux [DevTools](https://github.com/gaearon/redux-devtools)
|
59
|
+
|
60
|
+
**Use DevTools only in a development, below code has to be excluded in production.**
|
61
|
+
|
62
|
+
register in `react/index.js`:
|
63
|
+
|
64
|
+
```js
|
65
|
+
import DevTools from './containers/DevTools';
|
66
|
+
RWRRedux.registerContainer('DevTools', DevTools);
|
67
|
+
```
|
68
|
+
|
69
|
+
use in Rails view:
|
70
|
+
|
71
|
+
```erb
|
72
|
+
<%= redux_container 'DevTools' %>
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
## Issues
|
77
|
+
|
78
|
+
Found a bug in rwr-redux? Open an issue on [GitHub Issues](https://github.com/netguru/rwr-redux/issues).
|
79
|
+
|
80
|
+
## Pull requests
|
81
|
+
|
82
|
+
Interested in contributing to rwr-redux? That's great, and thank you for your interest!
|
83
|
+
|
84
|
+
After checking out the repo, run `bundle exec rake setup:all` to install every environment dependencies.
|
85
|
+
|
86
|
+
To get your contributions accepted, make sure:
|
87
|
+
|
88
|
+
* All the tests pass. Run `bundle exec rake test:all`.
|
89
|
+
* Any new code paths you've added are covered by tests.
|
90
|
+
* Describe your changes in pull request (what it adds, how to migrate from previous version etc.)
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
namespace :test do
|
5
|
+
desc 'Run all tests'
|
6
|
+
task all: [:node, :gem] do
|
7
|
+
puts 'Finished all tests, yay!'
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Run node package tests'
|
11
|
+
task :node do
|
12
|
+
sh %Q(npm test)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run gem tests'
|
16
|
+
task :gem do
|
17
|
+
sh %Q(bundle exec rspec spec/rwr-redux.rb)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task default: 'test:all'
|
22
|
+
|
23
|
+
namespace :setup do
|
24
|
+
desc 'Prepare every environment'
|
25
|
+
task all: [:node, :gem] do
|
26
|
+
puts 'Prepared all, yay!'
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Prepare node module dependencies'
|
30
|
+
task :node do
|
31
|
+
sh %Q(npm install)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Prepare gem dependencies'
|
35
|
+
task :gem do
|
36
|
+
sh %Q(bundle install)
|
37
|
+
end
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "react_webpack_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/js/.eslintrc
ADDED
data/js/src/index.js
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
import version from './version';
|
2
|
+
|
3
|
+
import React from 'react';
|
4
|
+
import { render, unmountComponentAtNode } from 'react-dom';
|
5
|
+
import { renderToString } from 'react-dom/server';
|
6
|
+
import { Provider } from 'react-redux'
|
7
|
+
|
8
|
+
import { isFunction, isReduxStore } from './utils/validators';
|
9
|
+
|
10
|
+
class RWRRedux {
|
11
|
+
constructor() {
|
12
|
+
this.version = version;
|
13
|
+
this.registeredStores = {};
|
14
|
+
this.mountedStores = {};
|
15
|
+
this.defaultStore = null;
|
16
|
+
this.containers = {};
|
17
|
+
|
18
|
+
this.registerStore = this.registerStore.bind(this);
|
19
|
+
this.mountStore = this.mountStore.bind(this);
|
20
|
+
this.getStore = this.getStore.bind(this);
|
21
|
+
this.registerContainer = this.registerContainer.bind(this);
|
22
|
+
this.getContainer = this.getContainer.bind(this);
|
23
|
+
this.createContainer = this.createContainer.bind(this);
|
24
|
+
this.createRootComponent = this.createRootComponent.bind(this);
|
25
|
+
this.renderContainer = this.renderContainer.bind(this);
|
26
|
+
this.unmountContainer = this.unmountContainer.bind(this);
|
27
|
+
this.renderContainerToString = this.renderContainerToString.bind(this);
|
28
|
+
}
|
29
|
+
|
30
|
+
registerStore(name, store) {
|
31
|
+
isFunction(store, `Error when registering '${name}' store: must be a function.`);
|
32
|
+
this.registeredStores[name] = store;
|
33
|
+
}
|
34
|
+
|
35
|
+
mountStore(name, props) {
|
36
|
+
const store = this.registeredStores[name];
|
37
|
+
isFunction(store, `Error when mounting '${name}' store: must be a function.`);
|
38
|
+
|
39
|
+
const storeObject = store(props);
|
40
|
+
isReduxStore(storeObject, `Error when mounting '${name}' store: must be a valid Redux store.`);
|
41
|
+
this.mountedStores[name] = storeObject;
|
42
|
+
this.defaultStore = storeObject;
|
43
|
+
}
|
44
|
+
|
45
|
+
getStore(name) {
|
46
|
+
if (name) {
|
47
|
+
return this.mountedStores[name];
|
48
|
+
} else {
|
49
|
+
return this.defaultStore;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
registerContainer(name, container) {
|
54
|
+
this.containers[name] = container;
|
55
|
+
}
|
56
|
+
|
57
|
+
getContainer(name) {
|
58
|
+
return this.containers[name];
|
59
|
+
}
|
60
|
+
|
61
|
+
createContainer(name) {
|
62
|
+
const constructor = this.getContainer(name);
|
63
|
+
return React.createElement(constructor);
|
64
|
+
}
|
65
|
+
|
66
|
+
createRootComponent(name, storeName) {
|
67
|
+
const container = this.createContainer(name);
|
68
|
+
return React.createElement(Provider, { store: this.getStore(storeName) }, container);
|
69
|
+
}
|
70
|
+
|
71
|
+
renderContainer(name, node, storeName) {
|
72
|
+
const rootComponent = this.createRootComponent(name, storeName);
|
73
|
+
render(rootComponent, node);
|
74
|
+
}
|
75
|
+
|
76
|
+
unmountContainer(node) {
|
77
|
+
unmountComponentAtNode(node);
|
78
|
+
}
|
79
|
+
|
80
|
+
renderContainerToString(name, storeName) {
|
81
|
+
const rootComponent = this.createRootComponent(name, storeName);
|
82
|
+
renderToString(rootComponent);
|
83
|
+
}
|
84
|
+
|
85
|
+
get storeIntegrationWrapper() {
|
86
|
+
return {
|
87
|
+
mount: function _mount(_, payload) {
|
88
|
+
this.mountStore(payload.name, payload.props);
|
89
|
+
}.bind(this)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
get containerIntegrationWrapper() {
|
94
|
+
return {
|
95
|
+
mount: function _mount(node, payload) {
|
96
|
+
this.renderContainer(payload.name, node, payload.storeName);
|
97
|
+
}.bind(this),
|
98
|
+
|
99
|
+
unmount: function _unmount(node) {
|
100
|
+
this.unmountContainer(node);
|
101
|
+
}.bind(this),
|
102
|
+
|
103
|
+
nodeRun: function _prerender(payload) {
|
104
|
+
return this.renderContainerToString(payload.name);
|
105
|
+
}.bind(this)
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
export default new RWRRedux;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
function _isFunction(func) {
|
2
|
+
return typeof func === 'function';
|
3
|
+
}
|
4
|
+
|
5
|
+
function _isObject(obj) {
|
6
|
+
return obj !== null && typeof obj === 'object';
|
7
|
+
}
|
8
|
+
|
9
|
+
function _isReduxStore(store) {
|
10
|
+
return (_isFunction(store.subscribe) &&
|
11
|
+
_isFunction(store.dispatch) &&
|
12
|
+
_isFunction(store.dispatch)
|
13
|
+
);
|
14
|
+
}
|
15
|
+
|
16
|
+
export function isFunction(func, errorMsg) {
|
17
|
+
if (!_isFunction(func)) throw new Error(errorMsg);
|
18
|
+
}
|
19
|
+
|
20
|
+
export function isReduxStore(store, errorMsg) {
|
21
|
+
if (!_isObject(store) || !_isReduxStore(store)) throw new Error(errorMsg);
|
22
|
+
}
|
data/js/src/version.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export default '0.1.0-alpha1';
|
data/js/test/index.js
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
import expect, { spyOn } from 'expect';
|
2
|
+
import { createStore } from 'redux'
|
3
|
+
import React from 'react';
|
4
|
+
import ReactDOM from 'react-dom';
|
5
|
+
import ReactDOMServer from 'react-dom/server';
|
6
|
+
|
7
|
+
import subject from '../src/index';
|
8
|
+
|
9
|
+
class AppContainer extends React.Component {
|
10
|
+
render() {
|
11
|
+
return <div>AppContainer</div>;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
const fakeReducer = function() {};
|
16
|
+
const validStore = function(initialState) {
|
17
|
+
return createStore(fakeReducer, initialState)
|
18
|
+
};
|
19
|
+
|
20
|
+
describe('RWRRedux', function () {
|
21
|
+
afterEach(function() {
|
22
|
+
subject.registeredStores = {};
|
23
|
+
subject.mountedStores = {};
|
24
|
+
subject.containers = {};
|
25
|
+
expect.restoreSpies();
|
26
|
+
});
|
27
|
+
|
28
|
+
describe('.version', function () {
|
29
|
+
it('is present', function () {
|
30
|
+
expect(subject.version).toNotEqual(undefined);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
describe('.constructor', function() {
|
35
|
+
it('intializes empty stores, mountedStores and containers dictionaries', function () {
|
36
|
+
expect(subject.registeredStores).toEqual({});
|
37
|
+
expect(subject.mountedStores).toEqual({});
|
38
|
+
expect(subject.containers).toEqual({});
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
describe('#registerStore', function() {
|
43
|
+
it('throws an error', function() {
|
44
|
+
expect(function() {
|
45
|
+
const invalidStore = {};
|
46
|
+
subject.registerStore('InvalidStore', invalidStore);
|
47
|
+
})
|
48
|
+
.toThrow(/Error when registering 'InvalidStore' store: must be a function./);
|
49
|
+
});
|
50
|
+
|
51
|
+
it('adds valid store to the storage', function() {
|
52
|
+
subject.registerStore('ValidStore', validStore);
|
53
|
+
|
54
|
+
expect(subject.registeredStores.ValidStore).toBe(validStore);
|
55
|
+
});
|
56
|
+
});
|
57
|
+
|
58
|
+
describe('#mountStore', function() {
|
59
|
+
it('throws an error when store is not a function', function(){
|
60
|
+
expect(function() {
|
61
|
+
subject.mountStore('InvalidStore', {});
|
62
|
+
})
|
63
|
+
.toThrow(/Error when mounting 'InvalidStore' store: must be a function./);
|
64
|
+
});
|
65
|
+
|
66
|
+
it('throws an error when store does not returns valid object', function(){
|
67
|
+
subject.registerStore('InvalidStore', function() { return 'store' });
|
68
|
+
expect(function() {
|
69
|
+
subject.mountStore('InvalidStore', {});
|
70
|
+
})
|
71
|
+
.toThrow(/Error when mounting 'InvalidStore' store: must be a valid Redux store./);
|
72
|
+
});
|
73
|
+
|
74
|
+
it('adds store to mountedStores storage and save as defaultStore', function() {
|
75
|
+
subject.registerStore('ValidStore', validStore);
|
76
|
+
const initialState = {};
|
77
|
+
subject.mountStore('ValidStore', initialState);
|
78
|
+
const storeObject = validStore(initialState);
|
79
|
+
|
80
|
+
expect(subject.mountedStores.ValidStore).toEqual(storeObject);
|
81
|
+
expect(subject.defaultStore).toEqual(storeObject)
|
82
|
+
});
|
83
|
+
});
|
84
|
+
|
85
|
+
describe('#getStore', function() {
|
86
|
+
it('returns undefined if store is not found', function() {
|
87
|
+
expect(subject.getStore('FakeStore')).toBe(undefined);
|
88
|
+
});
|
89
|
+
|
90
|
+
it('returns store by name from mountedStores storage', function() {
|
91
|
+
subject.registerStore('ValidStore', validStore);
|
92
|
+
subject.mountStore('ValidStore', {});
|
93
|
+
expect(subject.getStore('ValidStore')).toEqual(validStore({}));
|
94
|
+
});
|
95
|
+
|
96
|
+
it('returns default store when store\'s name is not given', function() {
|
97
|
+
subject.registerStore('ValidStore', validStore);
|
98
|
+
subject.mountStore('ValidStore', {});
|
99
|
+
|
100
|
+
expect(subject.getStore()).toEqual(validStore({}));
|
101
|
+
});
|
102
|
+
});
|
103
|
+
|
104
|
+
describe('#registerContainer', function() {
|
105
|
+
it('adds container to the storage', function() {
|
106
|
+
subject.registerContainer('AppContainer', AppContainer);
|
107
|
+
|
108
|
+
expect(subject.containers.AppContainer).toEqual(AppContainer);
|
109
|
+
});
|
110
|
+
});
|
111
|
+
|
112
|
+
describe('#getContainer', function() {
|
113
|
+
it('returns container by name', function() {
|
114
|
+
subject.registerContainer('AppContainer', AppContainer);
|
115
|
+
expect(subject.getContainer('AppContainer')).toEqual(AppContainer);
|
116
|
+
});
|
117
|
+
});
|
118
|
+
|
119
|
+
describe('#createContainer', function () {
|
120
|
+
it('creates redux container', function() {
|
121
|
+
subject.registerContainer('AppContainer', AppContainer);
|
122
|
+
const container = subject.createContainer('AppContainer');
|
123
|
+
|
124
|
+
expect(React.isValidElement(container)).toBe(true);
|
125
|
+
expect(container.type).toBe(AppContainer);
|
126
|
+
});
|
127
|
+
});
|
128
|
+
|
129
|
+
describe('#createRootComponent', function() {
|
130
|
+
it('creates redux root component', function() {
|
131
|
+
subject.registerStore('ValidStore', validStore);
|
132
|
+
const initialState = { fake: 'state' };
|
133
|
+
subject.mountStore('ValidStore', initialState);
|
134
|
+
subject.registerContainer('AppContainer', AppContainer);
|
135
|
+
const rootComponent = subject.createRootComponent('AppContainer', 'ValidStore');
|
136
|
+
|
137
|
+
expect(React.isValidElement(rootComponent)).toBe(true);
|
138
|
+
});
|
139
|
+
});
|
140
|
+
|
141
|
+
describe('#renderContainer', function() {
|
142
|
+
it('calls #createRootComponent and ReactDOM.render functions', function() {
|
143
|
+
const subjectSpy = spyOn(subject, 'createRootComponent');
|
144
|
+
const reactSpy = spyOn(ReactDOM, 'render');
|
145
|
+
|
146
|
+
subject.renderContainer('ContainerName', 'node', 'StoreName');
|
147
|
+
|
148
|
+
expect(subjectSpy.calls.length).toEqual(1);
|
149
|
+
expect(subjectSpy).toHaveBeenCalledWith('ContainerName', 'StoreName');
|
150
|
+
expect(reactSpy.calls.length).toEqual(1);
|
151
|
+
});
|
152
|
+
});
|
153
|
+
|
154
|
+
describe('#unmountContainer', function() {
|
155
|
+
const node = { nodeType: 1, nodeName: 'DIV' };
|
156
|
+
const unmountSpy = spyOn(ReactDOM, 'unmountComponentAtNode');
|
157
|
+
|
158
|
+
subject.unmountContainer(node);
|
159
|
+
|
160
|
+
expect(unmountSpy.calls.length).toEqual(1);
|
161
|
+
expect(unmountSpy).toHaveBeenCalledWith(node);
|
162
|
+
});
|
163
|
+
|
164
|
+
describe('#renderContainerToString', function() {
|
165
|
+
it('calls #createRootComponent and ReactDOM.renderToString', function() {
|
166
|
+
const subjectSpy = spyOn(subject, 'createRootComponent');
|
167
|
+
const reactSpy = spyOn(ReactDOMServer, 'renderToString');
|
168
|
+
|
169
|
+
subject.renderContainerToString('ContainerName', 'StoreName');
|
170
|
+
|
171
|
+
expect(subjectSpy.calls.length).toEqual(1);
|
172
|
+
expect(subjectSpy).toHaveBeenCalledWith('ContainerName', 'StoreName');
|
173
|
+
expect(reactSpy.calls.length).toEqual(1);
|
174
|
+
});
|
175
|
+
});
|
176
|
+
|
177
|
+
describe('#storeIntegrationWrapper.mount', function() {
|
178
|
+
it('calls #mountStore function', function() {
|
179
|
+
const mountStoreSpy = spyOn(subject, 'mountStore');
|
180
|
+
const payload = { name: 'StoreName', props: { fake: 'props' } };
|
181
|
+
|
182
|
+
subject.storeIntegrationWrapper.mount('', payload)
|
183
|
+
|
184
|
+
expect(mountStoreSpy.calls.length).toEqual(1);
|
185
|
+
expect(mountStoreSpy).toHaveBeenCalledWith(payload.name, payload.props);
|
186
|
+
});
|
187
|
+
});
|
188
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'react_webpack_rails/redux_integration/view_helpers'
|
2
|
+
|
3
|
+
module ReactWebpackRails
|
4
|
+
module ReduxIntegration
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer 'react_webpack_rails.redux_helpers.view_helpers' do
|
7
|
+
ActionView::Base.send :include, ViewHelpers
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ReactWebpackRails
|
2
|
+
module ReduxIntegration
|
3
|
+
module ViewHelpers
|
4
|
+
def redux_store(name, raw_props = {}, options = {})
|
5
|
+
react_element('redux-store', { name: name, props: serialize_props(raw_props) }, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def redux_container(name, options = {})
|
9
|
+
store_name = options.delete(:store_name)
|
10
|
+
react_element('redux-container', { name: name, storeName: store_name }, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def serialize_props(raw_props)
|
16
|
+
props = raw_props.as_json
|
17
|
+
return props unless Rails.application.config.react.camelize_props
|
18
|
+
ReactWebpackRails::Services::CamelizeKeys.call(props)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rwr-redux.rb
ADDED
data/package.json
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"name": "rwr-redux",
|
3
|
+
"version": "0.1.0-alpha1",
|
4
|
+
"description": "",
|
5
|
+
"main": "js/lib/index.js",
|
6
|
+
"files": [
|
7
|
+
"js/lib"
|
8
|
+
],
|
9
|
+
"scripts": {
|
10
|
+
"compile": "babel --presets es2015 -d js/lib/ js/src/",
|
11
|
+
"prepublish": "npm run compile",
|
12
|
+
"test": "mocha js/test --ui bdd --recursive --require babel-core/register"
|
13
|
+
},
|
14
|
+
"repository": {
|
15
|
+
"type": "",
|
16
|
+
"url": ""
|
17
|
+
},
|
18
|
+
"keywords": [],
|
19
|
+
"author": "",
|
20
|
+
"license": "",
|
21
|
+
"bugs": {
|
22
|
+
"url": ""
|
23
|
+
},
|
24
|
+
"homepage": "",
|
25
|
+
"peerDependencies": {
|
26
|
+
"react": "^0.14.0",
|
27
|
+
"react-dom": "^0.14.0",
|
28
|
+
"react-redux": "^4.4.0",
|
29
|
+
"redux": "^3.3.1"
|
30
|
+
},
|
31
|
+
"dependencies": {
|
32
|
+
"react-webpack-rails": "^0.1.0"
|
33
|
+
},
|
34
|
+
"devDependencies": {
|
35
|
+
"babel-cli": "^6.4.0",
|
36
|
+
"babel-core": "^6.4.0",
|
37
|
+
"babel-preset-es2015": "^6.3.0",
|
38
|
+
"babel-preset-react": "^6.3.0",
|
39
|
+
"eslint": "^1.10.3",
|
40
|
+
"eslint-config-airbnb": "^3.1.0",
|
41
|
+
"eslint-plugin-react": "^3.15.0",
|
42
|
+
"expect": "^1.13.4",
|
43
|
+
"history": "^1.17.0",
|
44
|
+
"mocha": "^2.3.4"
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'react_webpack_rails/redux_integration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rwr-redux'
|
8
|
+
spec.version = ReactWebpackRails::ReduxIntegration::VERSION
|
9
|
+
spec.authors = ['Kacper Goliński', 'Rafał Gawlik']
|
10
|
+
spec.email = ['react@netguru.co']
|
11
|
+
|
12
|
+
spec.summary = 'Redux integration for react_webpack_rails'
|
13
|
+
spec.description = ''
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
28
|
+
|
29
|
+
spec.add_dependency 'react_webpack_rails', '>= 0.1.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwr-redux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kacper Goliński
|
8
|
+
- Rafał Gawlik
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.10'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.10'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: react_webpack_rails
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.1.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.1.0
|
70
|
+
description: ''
|
71
|
+
email:
|
72
|
+
- react@netguru.co
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".babelrc"
|
78
|
+
- ".gitignore"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- js/.eslintrc
|
87
|
+
- js/src/index.js
|
88
|
+
- js/src/utils/validators.js
|
89
|
+
- js/src/version.js
|
90
|
+
- js/test/index.js
|
91
|
+
- lib/react_webpack_rails/redux_integration/engine.rb
|
92
|
+
- lib/react_webpack_rails/redux_integration/railtie.rb
|
93
|
+
- lib/react_webpack_rails/redux_integration/version.rb
|
94
|
+
- lib/react_webpack_rails/redux_integration/view_helpers.rb
|
95
|
+
- lib/rwr-redux.rb
|
96
|
+
- package.json
|
97
|
+
- redux_integration.gemspec
|
98
|
+
homepage: ''
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Redux integration for react_webpack_rails
|
122
|
+
test_files: []
|