server_component 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 9320945a81de39a89ab9095e72f82a47e72d66cc30a46a9156f89a8e8f7735bc
4
- data.tar.gz: 54494358d93080820cb79ef3743ecddf8a8d3dc4a2de167cf2435840b2c4408b
3
+ metadata.gz: 9bead1c946447ad4a8fec276be086f00c650c519c05aa8c8c9e5ca47d5b47015
4
+ data.tar.gz: 407725a376a34d739c9bd6e6ae1582abe5b82d14496a473d4ff1a93f0dbd6b68
5
5
  SHA512:
6
- metadata.gz: 9230c721a1efde5cdb1e9bd67cfadcd2de2b12ea5a3fde66e8abc07b362dfd625a2eb84137c2afe7c31975638fd888bd0361eaf0fa87d7d8b11bb34bc86e1aff
7
- data.tar.gz: b2afbce0ab6f87e36d4c1282ece5dc2bfd797036160ea5a5201fc294bc7b89a2d116ac72bc756a9481e9e252c4d4c4284c0243f2a378f41a948b8efcbb9ac7f2
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
- In the client code (with Babel >= 7):
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
- @new_state.member!(matches[1]).assign!(args[0]).as_statement!
14
+ @js.set! @new_state[matches[1]], args[0]
14
15
  elsif block_given?
15
- block_result = yield @prev_state.member!(name)
16
- @new_state.member!(name).assign!(block_result).as_statement!
16
+ block_result = yield @prev_state[name]
17
+ @js.set! @new_state[name], block_result
17
18
  else
18
- @new_state.member!(name)
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).as_statement!
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServerComponent
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -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.2'
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.2.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-10 00:00:00.000000000 Z
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.2'
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.2'
26
+ version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement