You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `hyperstack-loader` is a dynamically generated asset manifest that will load all your client side Ruby code. Make sure it is the last require in `app/assets/javascripts/application.js` file. That is it should be just before the final `require_tree` directive
106
+
### 3. Update the `application.js` file
101
107
102
-
`jQuery` is very nicely integrated with Hyperstack, and provides a well
103
-
documented uniform interface to the DOM. To use it require it and its Rails
104
-
counter part in `application.js` before the `hyperstack-loader`
108
+
The `hyperstack-loader` is a dynamically generated asset manifest that will load all your client side Ruby code. Make sure it is the last require in `app/assets/javascripts/application.js` file. That is it should be just *before* the final `require_tree` directive
105
109
106
110
```javascript
111
+
// assets/javascripts/application.js
112
+
...
107
113
//= require hyperstack-loader
108
114
//= require_tree .
109
115
```
110
-
> Note check to make sure jquery is not already being required.
111
116
112
-
### Add the `hyperstack` directories
117
+
### 4. Add the `hyperstack` directories
113
118
114
119
Hyperstack will load code out of the `app/hyperstack` directory. Within this directory there are typically the following subdirectories:
115
120
@@ -124,11 +129,11 @@ These directories are all optional. The `models`, `operations`, and `shared` su
124
129
125
130
Any other subdirectories will be treated as client only. The names listed above such as `components`, `stores` and `lib` are just conventions. For example you may prefer `client_lib`.
126
131
127
-
> Note that you will still have a`app/models` directory, which can be used to keep server-only models. This is useful for models that will never be accessed from the client to reduce payload size. You can also add an `app/operations` directory if you wish to have Operations that only run on the server.
132
+
> Note that you will still have the standard Rails`app/models` directory, which can be used to keep server-only models. This is useful for models that will never be accessed from the client to reduce payload size. You can also add an `app/operations` directory if you wish to have Operations that only run on the server.
128
133
>
129
-
> For security see the policy setup below.
134
+
> This does **not** effect security. See the section 7 for how Policies are setup.
130
135
131
-
### Add the HyperComponent base class
136
+
### 5. Add the HyperComponent base class
132
137
133
138
The Hyperstack convention is for each application to define a `HyperComponent` base class from which all of your other components will inherit. This follows the modern Rails convention used with Models and Controllers.
134
139
@@ -139,8 +144,8 @@ The typical `HyperComponent` class definition looks like this:
139
144
classHyperComponent
140
145
# All component classes must include Hyperstack::Component
141
146
includeHyperstack::Component
142
-
# The Observer module adds state handling
143
-
includeHyperstack::State::Observer
147
+
# The Observable module adds state handling
148
+
includeHyperstack::State::Observable
144
149
# The following turns on the new style param accessor
145
150
# i.e. param :foo is accessed by the foo method
146
151
param_accessor_style :accessors
@@ -151,9 +156,9 @@ end
151
156
base class `ApplicationComponent` more closely following the
152
157
rails convention.
153
158
154
-
### Replicate the `application_record.rb` file
159
+
### 6. Replicate the `application_record.rb` file
155
160
156
-
Model files typically inherit from the `ApplicationModel` class, so you must move the
161
+
Rails models files normally inherit from the `ApplicationModel` class, so you must move the
157
162
`app/models/application_record.rb` to `app/hyperstack/models/application_record.rb` so
158
163
that it is accessible both on the client and server.
> Note that the above is *not* a typo. Rails paths begin with
172
177
the *subdirectory* name. So `'models/application_record.rb'` means to search all directories for a file name `application_record.rb` in the `models`*subdirectory*
173
178
174
-
### Add a basic `application_policy.rb` file
179
+
### 7. Add a basic `application_policy.rb` file
175
180
176
-
Your server side model data is protected by *Policies* defined in Policy classes stored in the `app/policy` directory. The following file creates basic a*"wide open"* set of
181
+
Your server side model data is protected by *Policies* defined in Policy classes stored in the `app/policy` directory. The following file creates a basic*"wide open"* set of
177
182
policies for development mode. You will then need to add specific Policies to protect
178
183
your data in production mode.
179
184
@@ -205,15 +210,16 @@ end unless Rails.env.production?
205
210
> Note that regardless of whether models are public (i.e stored in the hyperstack/models
206
211
directory) or private, they are ultimately protected by the Policy system.
207
212
208
-
### Add the `hyperstack.rb` initializer file
213
+
### 8. Add the `hyperstack.rb` initializer file
209
214
210
215
Add the following file to the `config/initializers/` directory:
211
216
212
217
```ruby
213
218
# config/initializers/hyperstack.rb
214
219
Hyperstack.configuration do |config|
215
-
# If you are not using ActionCable,
220
+
# If you do not want to use ActionCable,
216
221
# see http://hyperstack.orgs/docs/models/configuring-transport/
222
+
# for setting up other options.
217
223
config.transport =:action_cable# or :pusher or :simple_poller
218
224
219
225
# typically you will want to develop with prerendering off, and
@@ -252,7 +258,63 @@ you will may want to direct the output to a dedicated log file for example.
252
258
253
259
### Integrate with webpacker
254
260
255
-
@barriehadfield - HELP!
261
+
The Rails webpacker gem will bundle up all your javascript assets including those used by Hyperstack such as React, and React-Router.
262
+
263
+
You can also easily add other NPM (node package manager) assets to the webpacker *pack files*.
264
+
265
+
Hyperstack will look for two webpacker pack files: one for packages that *only* run on the client side, and packages that can run on *both* the client, and during server prerendering.
266
+
> Prerendering builds the initial page view server side, and then delivers it to the client as a normal static HTML page. Attached to the HTML are flags that React will use update the page as components are re-rendered after the initial page load.
267
+
>
268
+
> This means that page load time is comparable to any other Rails view.
269
+
>
270
+
> But to make this work packages that rely on the `browser` object, cannot be used during prerendering. Well structured packages that depend on the `browser` object will have a way to run in the prerendering environment.
271
+
272
+
You will also need to fetch the packages, plus any of their dependencies and bring them into your build environment.
273
+
274
+
> Coming from Ruby this can be confusing as we are used to simply adding a dependency into the `Gemfile`, and then using bundler to both fetch dependencies, and produce the `Gemfile.lock` file.
275
+
>
276
+
> In the JS world its a two part process. Yarn fetches packages and their dependents, and maintains a `yarn.lock` file. The pack files specify how to package up the JS code, making it ready for delivery to the client.
277
+
278
+
#### Add the `client_and_server.js` pack file
279
+
280
+
* Note that this goes in a new directory: `app/javascripts/packs` *
281
+
282
+
```javascript
283
+
//app/javascript/packs/client_and_server.js
284
+
// these packages will be loaded both during prerendering and on the client
285
+
React =require('react'); // react-js library
286
+
History=require('history'); // react-router history library
0 commit comments