Skip to content

Commit 5942545

Browse files
committed
improved docs, added mount_component alias
1 parent f656d13 commit 5942545

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

docs/installation/installation.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ And for a full system that includes Webpack for managing javascript assets you w
1414

1515
## Creating a Test Rails App
1616

17-
You can install Hyperstack in an existing Rails apps, or you can create a new Rails app using the Rails `new` command. For example to create a new app called `MyApp` you would run
17+
You can install Hyperstack in existing Rails apps, or you can create a new Rails app using the Rails `new` command. For example to create a new app called `MyApp` you would run
1818

1919
```
2020
rails new MyApp -T
@@ -26,7 +26,7 @@ which will create a new directory called `MyApp`. *Be sure to cd into the new d
2626
2727
## Adding the Hyperstack gem
2828

29-
Add the rails-hyperstack gem to your Gemfile, and then bundle install. This can be done in one step by running:
29+
Once you have a new (or existing) Rails app, add the rails-hyperstack gem to your Gemfile, and then bundle install. This can be done in one step by running:
3030

3131
```
3232
bundle add 'rails-hyperstack', --version "~> 1.0.alpha1.0"
@@ -47,28 +47,32 @@ After the Hyperstack gem is installed you can do a full install by running:
4747
bundle exec rails hyperstack:install
4848
```
4949
This will install the following pieces:
50-
+ A skeleton top level router component named `App`
51-
+ A Rails route that will send all requests to that component
50+
+ A skeleton top level router component named `App` *(only on new apps)*
51+
+ A Rails route that will send all requests to that component *(only on new apps)*
5252
+ The webpacker gem and associated files to integrate Hyperstack with webpack
5353
+ HyperModel to give your client components access to your Rails models
5454
+ The Hotloader which will update the client when you make changes to code
5555

56-
Each of these pieces can be skipped or installed independently either using
56+
Each of the above pieces can be skipped or installed independently either using
5757
built in installers and generators, or manually as explained in the
5858
following sections.
5959

60-
At this point, you're fully installed.
60+
> The top level component, and route is only installed if a new Rails app is detected. Otherwise you will have to choose how you want to mount your components, depending on the needs of your application. See [How to add components](#<user-content-adding-a-single-component-to-your-application>) and [mount them](#<mounting-components>) for details.
6161
62-
If you're installing into a new rails app, you can run bundle exec foreman start
63-
to start the server, and "app" will display on the top left hand side of the page.
6462

65-
If you're installing into an existing Rails apps, you can run bundle exec foreman start
66-
to start the server, and your app should funcion exactly as it always has. From here, you'll need to
67-
[add a Hypercomponent](#<user-content-adding-a-single-component-to-your-application>)
68-
to have Hyperstack funcionality.
63+
At this point you're fully installed.
64+
65+
If you installed into a new rails app, you can run bundle exec foreman start
66+
to start the server, and **App** will display on the top left hand side of the page. You will find the `App` component in the `app/hyperstack/components/app.rb` file. If you edit this file and save you should see the changes reflected in the browser.
67+
68+
If you installed into an existing Rails apps, you can run bundle exec foreman start
69+
to start the server, and your app should function exactly as it always has. From here, you'll need to start adding components and
70+
and mounting them from either a view or a controller. See [How to add components](#<user-content-adding-a-single-component-to-your-application>) and [mount them](#<mounting-components>) for details.
6971

7072
## Summary of Installers and Generators
7173

74+
The following sections details the installers and generators you can use for for full control of the installation process. Details are also given on exactly what each installer and generator does if you want to manually apply the step or modify it to your needs.
75+
7276
```
7377
bundle exec ... # for best results always use bundle exec!
7478
rails hyperstack:install # full system install
@@ -135,7 +139,7 @@ The `models`, `operations`, and `shared` directories are *isomorphic*. That is t
135139
be run on both the Rails server and on the client. All other directories (regardless of the name)
136140
will only be visible on the client and during prerendering.
137141

138-
These directories will be created as needed by the installers and generators, or you can create them yourself as needed.
142+
These directories will be created as required by the installers and generators, or you can create them yourself as needed.
139143

140144
## Adding a Single Component to Your Application
141145

@@ -174,13 +178,13 @@ end
174178
bundle exec rails g hyper:component Test --base-class=ApplicationComponent
175179
```
176180
> You can also override the base class for the entire application by setting
177-
> the `component_base_class` config setting. See the last section for details.
181+
> the `component_base_class` config setting. See [Summary of Hyperstack Configuration Switches](#<summary-of-hyperstack-configuration-switches>) for details.
178182
179183
## Mounting Components
180184

181185
Components render (or *mount*) other components in a tree-like fashion. You can mount the top level component of the tree in three different ways:
182186
+ Render it from a controller using the `render_component` method
183-
+ Mount it from within a view using the `render_component` view helper
187+
+ Mount it from within a view using the `react_component` view helper
184188
+ Route to it from the Rails router
185189

186190
#### Rendering from a Controller Action
@@ -205,14 +209,17 @@ and override the default layout
205209
```ruby
206210
render_component 'Dashboard', {user: @user}, layout: :none
207211
```
212+
> Notice how `render_component` works very much like the standard Rails `render` method, except a component is rendered instead of a view.
208213
209-
#### Mounting from Within a View
214+
#### Mounting from Within a View or Layout
210215

211216
For example
212217
```erb
213-
<%= react_component 'Dashboard', user: @user %>
218+
<%= mount_component 'Dashboard', user: @user %>
214219
```
215-
> Note that you may have several component trees mounted in a single page using the `render_component` helper. While this is not typical for a clean sheet Hyperstack design, it is useful when mixing Hyperstack with legacy applications.
220+
will display the `Dashboard` component at this position in the
221+
code, very similar to displaying a view or partial.
222+
> Note that you may have several component trees mounted in a single page using the `mount_component` helper. While this is not typical for a clean sheet Hyperstack design, it is useful when mixing Hyperstack with legacy applications.
216223
217224

218225
#### Directly Routing to a Component
@@ -301,7 +308,7 @@ Using the Rails `webpacker` gem you can easily add other NPM (node package manag
301308
For details on how to import and use NPM packages in your application see [Importing React Components](https://hyperstack.org/edge/docs/dsl-client/components#javascript-components)
302309

303310
To integrate webpacker with an existing Hyperstack application - for example if you just added a couple of components and now
304-
want to try webpacker - use the hyperstack:install:webpack task:
311+
want to try webpacker - use the `hyperstack:install:webpack` task:
305312
```
306313
bundle exec rails hyperstack:install:webpack
307314
```
@@ -338,7 +345,7 @@ bundle exec rails webpacker:install
338345

339346
Webpacker uses manifests to determine how to package up assets. Hyperstack depends on two manifests: One that builds assets that are loaded both during prerendering **and** on the client, and a second that is **only** loaded on the client.
340347

341-
> 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.
348+
> 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 to update the page as components are re-rendered after the initial page load.
342349
>
343350
> This means that page load time is comparable to any other Rails view, and that Rails can cache the pages like any other view.
344351
>
@@ -470,7 +477,9 @@ This policy specifies the following:
470477
As your application develops you can begin defining more restrictive policies (only allowing Users to see their own data for example)
471478

472479
> Note: The policy mechanism does not depend on [Pundit](https://github.com/varvet/pundit) but is compatible with it. You can add pundit style
473-
policies for legacy parts of your system.
480+
policies for legacy parts of your system.
481+
>
482+
> For details on creating policies see the [policy documentation](https://github.com/hyperstack-org/hyperstack/blob/edge/docs/dsl-isomorphic/hyper-policy.md).
474483
475484
#### Moving the `application_record.rb` File.
476485

@@ -498,7 +507,7 @@ So to prevent that you need to add this file to `app/models`
498507
require 'models/application_record.rb'
499508
```
500509
> Note that the last line is *not* a typo. Rails paths begin with
501-
the *subdirectory* name. So `'models/application_record.rb'` means to search all directories for a file name `application_record.rb` in the `models` *subdirectory*
510+
a *subdirectory* name. So `'models/application_record.rb'` means to search all app directories for a file name `application_record.rb` in a `models` *subdirectory*
502511

503512
Thus Rails will find `app/models/application_record.rb` where it expects it, but that file simply requires the real `application_record.rb` file from the `app/hyperstack/models` directory so everybody is happy.
504513

@@ -521,7 +530,6 @@ You can manually perform these steps following these instructions.
521530

522531
By default the Hotloader is **not** included in the hyperstack manifest so the first step is to import it using `config/initializers/hyperstack.rb` initializer file:
523532

524-
Note that
525533
```ruby
526534
# config/initializers/hyperstack.rb
527535
Hyperstack.configuration do |config|
@@ -563,7 +571,7 @@ Now go into your editor and make a change to a component. You should see the br
563571
#### Adding the Foreman Gem and Procfile
564572

565573
Having to start (and stop) two separate shells is painful so you can add the `foreman` gem which will manage all that for you. Add
566-
the `foreman` to the development section of your gem file and bundle install. You can do this in one step by running:
574+
the `foreman` gem to the development section of your Gemfile and bundle install. You can do this in one step by running:
567575
```ruby
568576
bundle add foreman --group development
569577
```
@@ -592,7 +600,7 @@ Hyperstack.configuration do |config|
592600
# set the component base class
593601
config.component_base_class = 'HyperComponent' # i.e. 'ApplicationComponent'
594602

595-
# prerendering is default :off, you should wait until your
603+
# prerendering is by default :off. You should wait until your
596604
# application is relatively well debugged before turning on.
597605
config.prerendering = :off # or :on
598606

@@ -606,7 +614,6 @@ Hyperstack.configuration do |config|
606614
# non-server process, Hyperstack needs to forward the change notification
607615
# to the server for push broadcasting. This value controls how long
608616
# Hyperstack will wait to hear back from the server.
609-
610617
config.send_to_server_timeout = 10 # seconds or nil for no timeout
611618

612619
# pusher specific setting. If you are already using pusher you
@@ -617,14 +624,14 @@ Hyperstack.configuration do |config|
617624
# you may want to switch this like this: = Rails.env.debug?
618625
config.client_logging = true
619626

620-
# Don't setup a session channel. This is mainly useful in test specs
627+
# Setup a session channel. Turning this off is mainly useful in test specs
621628
config.connect_session = true
622629

623630
# if you need to change the hotloader port
624631
config.hotloader_port = 25222 # note also update your proc file as well
625632

626633
# turn pinging on if your hotloader connection keeps dropping
627-
config.hotloader_ping = nil
634+
config.hotloader_ping = nil # 10 seconds for example
628635

629636
# callback mapping allows the hotloader to reprogram callbacks
630637
# however it adds additional overhead on first load. On large systems
@@ -646,7 +653,7 @@ end
646653

647654
# Hyperstack provides a hook to aid in debugging communication problems. The following
648655
# code block adds a useful server side log message. You may want to change this to
649-
# a specific logging location, or on occassion add a debug break point instead of logging
656+
# a specific logging location, or on occasion add a debug break point instead of logging
650657

651658
module Hyperstack
652659
def self.on_error(operation, err, params, formatted_error_message)

ruby/hyper-component/lib/hyperstack/internal/component/rails/component_mount.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ def footers
5050
end
5151
end
5252
end
53+
54+
55+
module React
56+
module Rails
57+
module ViewHelper
58+
alias mount_component react_component
59+
end
60+
end
61+
end

ruby/hyper-component/lib/hyperstack/internal/component/rails/controller_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def render_component(*args)
2222
@render_params = args.shift || {}
2323
options = args[0] || {}
2424
return if performed?
25-
render inline: '<%= react_component @component_name, @render_params %>',
25+
render inline: '<%= mount_component @component_name, @render_params %>',
2626
layout: options.key?(:layout) ? options[:layout].to_s : :default
2727
rescue Exception => e
2828
m = /^RuntimeError: Hyperstack::Internal::Component::Redirect (.+) status: (.+)$/.match(e.message)

0 commit comments

Comments
 (0)