|
| 1 | +## Upgrade Instructions - Part I |
| 2 | + |
| 3 | +### 1. Update your gemfile |
| 4 | + |
| 5 | +```ruby |
| 6 | +gem 'rails-hyperstack', '~> 1.0.alpha1.5' |
| 7 | +gem 'hyper-spec', '~> 1.0.alpha1.5' # if using hyper-spec |
| 8 | +``` |
| 9 | + |
| 10 | +remove any references to hotloader stuff. |
| 11 | + |
| 12 | +### 2. Move `app/hyperloop` directory to `app/hyperstack` |
| 13 | + |
| 14 | +the internal directories can remain (i.e. components, models, etc) |
| 15 | + |
| 16 | +### 3. Double check `application_record.rb` files are correct. |
| 17 | + |
| 18 | +Your main definition of `ApplicationRecord` should be in `app/hyperstack/models/application_record.rb` |
| 19 | + |
| 20 | +Meanwhile the contents of `app/models/application_record.rb` should look like this: |
| 21 | + |
| 22 | +```ruby |
| 23 | +# app/models/application_record.rb |
| 24 | +# the presence of this file prevents rails migrations from recreating application_record.rb |
| 25 | +# see https://github.com/rails/rails/issues/29407 |
| 26 | + |
| 27 | +require 'models/application_record.rb' |
| 28 | +``` |
| 29 | + |
| 30 | +### 4. Change the component base class from `Hyperloop::Component` to `HyperComponent` |
| 31 | + |
| 32 | +Hyperstack now follows the Rails convention used by ApplicationRecord and ApplicationController |
| 33 | +of having an application defined base class. |
| 34 | + |
| 35 | +Create a `app/hyperstack/components/hyper_component.rb` base class: |
| 36 | + |
| 37 | +```ruby |
| 38 | +# app/hyperstack/components/hyper_component.rb |
| 39 | +class HyperComponent |
| 40 | + def self.inherited(child) |
| 41 | + child.include Hyperstack::Component |
| 42 | + child.param_accessor_style :legacy # use the hyperloop legacy style param accessors |
| 43 | + child.include Hyperstack::Legacy::Store # use the legacy state definitions, etc. |
| 44 | + end |
| 45 | +end |
| 46 | +``` |
| 47 | + |
| 48 | +Now global search and replace all references to `Hyperloop::Component` to `HyperComponent` |
| 49 | + |
| 50 | +### 5. Update app/assets/javascript/application.js |
| 51 | + |
| 52 | +The last lines of `app/assets/javascripts/application.js` should look like this: |
| 53 | + |
| 54 | +```javascript |
| 55 | +//= require hyperstack-loader |
| 56 | +//= require_tree . |
| 57 | +``` |
| 58 | + |
| 59 | +Note: remove any lines mentioning hotloader. |
| 60 | + |
| 61 | +### 6. Update items related to Hotloader |
| 62 | + |
| 63 | +If you are using the hot loader, and foreman (i.e you have a Procfile) then your procfile will look like this: |
| 64 | +```text |
| 65 | +# Procfile |
| 66 | +web: bundle exec rails s -p 3004 -b 0.0.0.0 |
| 67 | +hot: bundle exec hyperstack-hotloader -p 25223 -d app/hyperstack/ |
| 68 | +``` |
| 69 | + |
| 70 | +The hotloader gem itself should be removed from the gemfile. |
| 71 | + |
| 72 | +In the hyperstack initializer there should be this line: |
| 73 | +```ruby |
| 74 | + Hyperstack.import 'hyperstack/hotloader', 'client_only: true if Rails.env.development?' |
| 75 | +``` |
| 76 | + |
| 77 | +remove any other references to hotloader in the initializer, and in `app/assets/javascripts/application.js` |
| 78 | + |
| 79 | +### 7. Update the initializer |
| 80 | + |
| 81 | +Rename `config/initializers/hyperloop.rb` to `config/initializers/hyperstack.rb` |
| 82 | + |
| 83 | +### 8. Change Element to jQ |
| 84 | + |
| 85 | +If you are using jQuery, you will have things like `Element['#some-id'].focus()` etc. |
| 86 | +These need to change to `jQ[...].focus()` etc. |
| 87 | + |
| 88 | +### 9. `IsomorphicHelpers` changes to `Hyperstack::Component::IsomorphicHelpers` |
| 89 | + |
| 90 | +search and replace... |
| 91 | + |
| 92 | +### 10. Change name of Hyperloop::... to Hyperstack:: |
| 93 | + |
| 94 | +If at this point you have other classes and methods under the `Hyperloop` namespace, you will have to find |
| 95 | +the equivilent class or method under Hyperstack. Its going to be a case by case basis. Let us know if you need help, and we can |
| 96 | +add each case to this document. |
| 97 | + |
| 98 | +### 11. Remove any patches |
| 99 | + |
| 100 | +If you have any patches to Hyperloop modules or classes, you probably don't need (or want them any more) |
| 101 | + |
| 102 | +## Upgrade Instructions Part II |
| 103 | + |
| 104 | +Once your app is working on the latest Hyperstack, you will want to upgrade to the latest Hyperstack syntax. This can be done gradually |
| 105 | + |
| 106 | +### 1. Tag names |
| 107 | + |
| 108 | +Tag names should all be upcased. i.e. `DIV`, `UL`, `LI`, `SPAN` etc. The lower case syntax is deprecated so this should be updated. |
| 109 | + |
| 110 | +### 2. Param accessors |
| 111 | + |
| 112 | +The legacy syntax to access params was `params.foo`. The standard approach now is to just to use `foo`. |
| 113 | + |
| 114 | +To change this you will need to change `param_accessor_style :legacy` to `param_accessor_style :accessor` in your `HyperComponent` definition. |
| 115 | + |
| 116 | +Then you should be able to do a global search and delete in the component directory of `params.`. |
| 117 | + |
| 118 | +### 3. State definition mutators, and accessors. |
| 119 | + |
| 120 | +State is now represented by instance variables. No special syntax is needed to declare a state variable. |
| 121 | + |
| 122 | +To access a state variable local to a component all you need to do is read the instance variable in the usual way. |
| 123 | + |
| 124 | +To update the state variable (or its contents) you prefix the operation with the mutate method. |
| 125 | + |
| 126 | +For example `mutate @foo[:bar] = 12` would mutate a hash named @foo. |
| 127 | + |
| 128 | +Once all your state accessors are updated you can remove the |
| 129 | + |
| 130 | +```ruby |
| 131 | + child.include Hyperstack::Legacy::Store # use the legacy state definitions, etc. |
| 132 | +``` |
| 133 | + |
| 134 | +from your `HyperComponent` base class. |
| 135 | + |
| 136 | +### 4. Other legacy behaviors |
| 137 | + |
| 138 | +Should be flagged by warnings in console.log. Update as instructed. |
| 139 | + |
0 commit comments