server_component 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/app/helpers/server_component_helper.rb +8 -7
- data/lib/server_component/version.rb +1 -1
- data/server_component.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bead1c946447ad4a8fec276be086f00c650c519c05aa8c8c9e5ca47d5b47015
|
4
|
+
data.tar.gz: 407725a376a34d739c9bd6e6ae1582abe5b82d14496a473d4ff1a93f0dbd6b68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0631f5f4c76228277c471ebd80592210f50c5d0b5ff46cc2da25ea2672b921e8da64dda6d857c672a767a469d25c40554e084c10976c9c210058ad75347a5e1d
|
7
|
+
data.tar.gz: 908494d1f9e3b908a083a3af30ad397ea50998d85f5aeee9b32c356d934cc77b4fed1a6610c76598db82f06313e2dfee02d50291353e6d3e83d7f527f10df5cc
|
data/README.md
CHANGED
@@ -19,6 +19,12 @@ Run this command to initialize configuration file and base classes.
|
|
19
19
|
$ rails generate server_component:install
|
20
20
|
```
|
21
21
|
|
22
|
+
Add the following line into `config/application.rb`.
|
23
|
+
|
24
|
+
```rb
|
25
|
+
config.autoload_paths << Rails.root.join('component_routers')
|
26
|
+
```
|
27
|
+
|
22
28
|
## Getting Started
|
23
29
|
|
24
30
|
Add a new component controller:
|
@@ -55,7 +61,9 @@ class ApiComponentRouter < ServerComponent::ComponentRouter
|
|
55
61
|
end
|
56
62
|
```
|
57
63
|
|
58
|
-
|
64
|
+
Install [server_component](https://github.com/effective-spa/server_component) of NPM package in your frontend module.
|
65
|
+
|
66
|
+
Here is a sample client code (with Babel >= 7 and decorator):
|
59
67
|
|
60
68
|
```js
|
61
69
|
import React, { Component } from 'react';
|
@@ -96,6 +104,18 @@ class Main extends Component {
|
|
96
104
|
ReactDOM.render(<Main />, document.getElementById('root'));
|
97
105
|
```
|
98
106
|
|
107
|
+
If you don't use decorators, here's an alternative:
|
108
|
+
|
109
|
+
```js
|
110
|
+
import ServerComponent, { connectServer, consume } from 'server_component';
|
111
|
+
|
112
|
+
const CounterContainer = connectServer(class extends Component {}, 'counter');
|
113
|
+
|
114
|
+
const CounterBody = consume(class extends Component {
|
115
|
+
:
|
116
|
+
}, 'counter');
|
117
|
+
```
|
118
|
+
|
99
119
|
## API Documentation
|
100
120
|
|
101
121
|
(TODO)
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module ServerComponentHelper
|
4
4
|
class SetStateDSL
|
5
|
-
def initialize(new_state, prev_state)
|
5
|
+
def initialize(jsrb, new_state, prev_state)
|
6
|
+
@js = jsrb
|
6
7
|
@new_state = new_state
|
7
8
|
@prev_state = prev_state
|
8
9
|
end
|
@@ -10,12 +11,12 @@ module ServerComponentHelper
|
|
10
11
|
# rubocop:disable Style/MethodMissingSuper
|
11
12
|
def method_missing(name, *args)
|
12
13
|
if (matches = name.to_s.match(/^(.+)=$/))
|
13
|
-
@
|
14
|
+
@js.set! @new_state[matches[1]], args[0]
|
14
15
|
elsif block_given?
|
15
|
-
block_result = yield @prev_state
|
16
|
-
@
|
16
|
+
block_result = yield @prev_state[name]
|
17
|
+
@js.set! @new_state[name], block_result
|
17
18
|
else
|
18
|
-
@new_state
|
19
|
+
@new_state[name]
|
19
20
|
end
|
20
21
|
end
|
21
22
|
# rubocop:enable Style/MethodMissingSuper
|
@@ -24,7 +25,7 @@ module ServerComponentHelper
|
|
24
25
|
def set_state(jsrb) # rubocop:disable Naming/AccessorMethodName
|
25
26
|
new_state = jsrb.var! { {} }
|
26
27
|
prev_state = jsrb.expr.component.state
|
27
|
-
yield SetStateDSL.new(new_state, prev_state)
|
28
|
-
jsrb.expr.component.setState.call(new_state)
|
28
|
+
yield SetStateDSL.new(jsrb, new_state, prev_state)
|
29
|
+
jsrb.do! jsrb.expr.component.setState.call(new_state)
|
29
30
|
end
|
30
31
|
end
|
data/server_component.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
|
-
spec.add_runtime_dependency 'jsrb', '~> 0.
|
34
|
+
spec.add_runtime_dependency 'jsrb', '~> 0.3'
|
35
35
|
spec.add_runtime_dependency 'rails', '~> 5.0', '>= 5.0.0'
|
36
36
|
|
37
37
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shun MIZUKAMI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsrb
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|