Skip to content

Commit

Permalink
further fix to #181
Browse files Browse the repository at this point in the history
  • Loading branch information
catmando committed May 2, 2019
1 parent 9ff02a7 commit f800705
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
60 changes: 57 additions & 3 deletions docs/installation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ These are the various parts of the system that must be updated for Hyperstack:

+ Insure yarn is loaded
+ Add the gems
+ Update the `application.js` files
+ Add the `hyperstack` directories and files
+ Update the `application.js` file
+ Add the `hyperstack` directories
+ Add the `HyperComponent` base class
+ Replicate the `application_record.rb` file
+ Add the `policy` directory and a base `application_policy.rb` file
+ Add the `hyperstack.rb` initializer file
+ Integrate with webpacker
Expand All @@ -65,11 +67,63 @@ See https://yarnpkg.com/en/docs/install for details
Add
```ruby
gem 'rails-hyperstack', '~> 1.0.alpha1.0'
gem 'webpacker'
gem 'webpacker' # if not already present
# foreman manages multiple processes, its needed with hotloader only
gem 'foreman', group: :development
```

Then `bundle install`.

And if you just added webpacker make sure to run `bundle exec rails webpacker:install`

### Update the `application.js` file

The `hyperstack-loader` is a dynamically generated asset that will load all your client side Ruby code. Make it is the last require in `app/assets/javascripts/application.js` file.

`jQuery` is very nicely integrated with Hyperstack, and provides a well
documented uniform interface to the DOM. To use it require it and its Rails
counter part in `application.js` before the `hyperstack-loader`

```javascript
//= require jquery
//= require jquery_ujs
//= require hyperstack-loader
```

### Add the `hyperstack` directories

Hyperstack will load code out of the `app/hyperstack` directory. Within this directory there are typically the following subdirectories:

+ `app/hyperstack/components` - Component classes (client only)
+ `app/hyperstack/models` - Shared active record model classes
+ `app/hyperstack/operations` - Shared operation classes
+ `app/hyperstack/stores` - Other data stores (client only)
+ `app/hyperstack/shared` - Misc shared modules and classes
+ `app/hyperstack/lib` - Client only libraries

These directories are all optional. The `models`, `operations`, and `shared` subdirectories are both used on the client, and will be also included as part of the Rails constant lookup search path.

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`.

> 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.
### Add the HyperComponent base class

The Hyperstack convention is for each application to define a `HyperComponent` base class, from which all of your other components will inherit from. This follows the modern Rails convention used with Models and Controllers.

The typical `HyperComponent` class definition looks like this:

```ruby
# app/hyperstack/hyper_component.rb
class HyperComponent
# All component classes must include Hyperstack::Component
include Hyperstack::Component
# The Observer module adds state handling
include Hyperstack::State::Observer
# The following turns on the new style param accessor
# i.e. param :foo is accessed by the foo method
param_accessor_style :accessors
end
```

> Note that this is only convention. The Hyperstack system assumes nothing about HyperComponent or how you define components. Any class that includes the `Hyperstack::Component` module will be a component.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def find_component(name)

def lookup_const(name)
return nil unless name =~ /^[A-Z]/
scopes = self.class.name.to_s.split('::').inject([Module]) do |nesting, next_const|
scopes = self.class.name.to_s.split('::').inject([Object]) do |nesting, next_const|
nesting + [nesting.last.const_get(next_const)]
end.reverse
scope = scopes.detect { |s| s.const_defined?(name, false) }
Expand Down

0 comments on commit f800705

Please sign in to comment.