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
{{ message }}
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
<h3id="components-are-just-state-machines">Components are Just State Machines</h3>
1026
1030
@@ -1040,14 +1044,14 @@ <h3 id="what-components-should-have-state">What Components Should Have State?</h
1040
1044
1041
1045
<p>A common pattern is to create several stateless components that just render data, and have a stateful component above them in the hierarchy that passes its state to its children via <code>params</code>. The stateful component encapsulates all of the interaction logic, while the stateless components take care of rendering data in a declarative way.</p>
1042
1046
1043
-
<h3id="what-should-go-in-state">What Should Go in State?</h3>
1047
+
<h3id="what-should-go-in-state">What <em>Should</em> Go in State?</h3>
1044
1048
1045
1049
<p><strong>State should contain data that a component's event handlers, timers, or http requests may change and trigger a UI update.</strong></p>
1046
1050
1047
1051
<p>When building a stateful component, think about the minimal possible representation of its state, and only store those properties in <code>state</code>. Add to your class methods to compute higher level values from your state variables. Avoid adding redundant or computed values as state variables as
1048
1052
these values must then be kept in sync whenever state changes.</p>
1049
1053
1050
-
<h3id="what-shouldnt-go-in-state">What Shouldn't Go in State?</h3>
1054
+
<h3id="what-shouldnt-go-in-state">What <em>Shouldn't</em> Go in State?</h3>
1051
1055
1052
1056
<p><code>state</code> should only contain the minimal amount of data needed to represent your UI's state. As such, it should not contain:</p>
<p>Managing state between components is best done using Stores as many Components can access one store. This saves passing data btween Components. Please see the <ahref="/docs/stores/overview">Store documentation</a> for details.</p>
1196
+
<p>Managing state between components is best done using Stores as many Components can access one store. This saves passing data btween Components. Please see the <ahref="/docs/stores/docs">Store documentation</a> for details.</p>
@@ -1253,40 +1257,44 @@ <h3 id="mixins-and-inheritance">Mixins and Inheritance</h3>
1253
1257
</code></pre>
1254
1258
<p>One common use case is a component wanting to update itself on a time interval. It's easy to use the kernel method <code>every</code>, but it's important to cancel your interval when you don't need it anymore to save memory. React provides <ahref="/docs/working-with-the-browser.html#component-lifecycle">lifecycle methods</a> that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide a React friendly <code>every</code> function that will automatically get cleaned up when your component is destroyed.</p>
1255
1259
1256
-
<p>```ruby runable
1257
-
module ReactInterval</p>
1260
+
<divclass="codemirror-live-edit"
1261
+
data-heading="Using state"
1262
+
data-rows=33
1263
+
data-top-level-component="TickTock">
1264
+
<pre>
1265
+
module ReactInterval
1258
1266
1259
-
<p>def self.included(base)
1267
+
def self.included(base)
1260
1268
base.before_mount do
1261
1269
@intervals = []
1262
-
end</p>
1263
-
<preclass="highlight plaintext"><code>base.before_unmount do
1264
-
@intervals.each(&:stop)
1265
-
end
1266
-
</code></pre>
1267
-
<p>end</p>
1270
+
end
1268
1271
1269
-
<p>def every(seconds, &block)
1270
-
Kernel.every(seconds, &block).tap { |i| @intervals << i }
"Hyperloop has been running for #{state.seconds} seconds".para
1293
+
render(DIV)do
1294
+
"Hyperloop has been running for #{state.seconds} seconds".para
1287
1295
end
1288
1296
end
1289
-
```</p>
1297
+
</pre></div>
1290
1298
1291
1299
<p>Notice that TickTock effectively has two before_mount callbacks, one that is called to initialize the <code>@intervals</code> array and another to initialize <code>state.seconds</code></p>
1292
1300
@@ -1421,27 +1429,31 @@ <h4 id="the-children-method">The children method</h4>
1421
1429
1422
1430
<p>The instance method <code>children</code> returns an enumerable that is used to access the unrendered children of a component.</p>
<p>If you are in the business of importing components with a tool like Webpack, then you will need to let Webpack (or whatever dependency manager you are using) take care of including the React source code. Just make sure that you are <em>not</em> including it on the ruby side of things. Hyperloop is currently tested with React versions 13, 14, and 15, so its not sensitive to the version you use.</p>
1920
1932
1921
1933
<p>However it gets a little tricky if you are using the react-rails gem. Each version of this gem depends on a specific version of React, and so you will need to manually declare this dependency in your Javascript dependency manager. Consult this <ahref="https://github.com/reactjs/react-rails/blob/master/VERSIONS.md">table</a> to determine which version of React you need. For example assuming you are using <code>npm</code> to install modules and you are using version 1.7.2 of react-rails you would say something like this:</p>
<p>See <ahref="/tutorials/hyperlooprails/webpack/">{ NPM and Webpack Tutorial }</a> or <ahref="/tutorials/hyperlooprails/hyperloop-rails-webpackergem-helloworld/">{ Webpacker GEM Tutorial }</a> for more information.</p>
1937
+
1924
1938
<h4id="using-webpack">Using Webpack</h4>
1925
1939
1926
1940
<p>Just a word on Webpack: If you a Ruby developer who is new to using Javascript libraries then we recommend using Webpack to manage javascript component dependencies. Webpack is essentially bundler for Javascript. Please see our Tutorials section for more information.</p>
@@ -1979,7 +1993,7 @@ <h4 id="opal-under-the-covers">Opal under the covers</h4>
1979
1993
<p>Hyperloop Components are a DSL wrapper of React which uses Opal to compile Ruby code to ES5 native JavaScript. If you have not used Opal before then you should at a minimum read the excellent guides as they will teach you enough Opal to get you started with Hyperloop.</p>
<p>Upto Rails 4.2, all models inherited from <code>ActiveRecord::Base</code>. But starting from Rails 5, all models will inherit from <code>ApplicationRecord</code>.</p>
630
+
<p>Up until Rails 4.2, all models inherited from <code>ActiveRecord::Base</code>. But starting from Rails 5, all models will inherit from <code>ApplicationRecord</code>.</p>
628
631
629
632
<p>To accommodate this change, the following file has been automatically added to models in Rails 5 applications.</p>
<p>For Hyperloop to see this change, this file needs to be moved (or copied if you have some server-side models) to the <code>apps/hyperloop</code> folder.</p>
<p>In order to prevent unauthorized access to information like scope counts, lists of record ids, etc, Hyperloop now (see issue <ahref="https://github.com/ruby-hyperloop/hyper-mesh/issues/43">https://github.com/ruby-hyperloop/hyper-mesh/issues/43</a>) requires you explicitly allow scopes to be viewed on the client, otherwise you will get an AccessViolation.</p>
643
+
644
+
<p>To globally allow access to all scopes add this to the ApplicationRecord class</p>
<p>Hyperloop uses a subset of the standard ActiveRecord API to give your Isomorphic Components, Operations and Stores access to your server side Models. As much as possible Hyperloop follows the syntax and semantics of ActiveRecord. </p>
<p>React and ReactDOM are being brought in by Hyperloop, so we need to let Webpack know that these libraries are external so we do not end up with more than one copy of React running. Note that you will also need to do this for your production environment.</p>
522
522
523
-
<p>In the <code>module.export</code> block, add the following to <code>development.js</code>:</p>
<p>And <ahref="/docs/advancedconfiguration/#auto_config">{ set Hyperloop in AUTO-CONFIG MODE = OFF }</a> in order to choose manually which libraries will be imported.</p>
578
+
571
579
<h4id="step-1-8-adding-css-pack-files-to-the-asset-pipeline">Step 1.8 - Adding CSS pack files to the asset pipeline</h4>
0 commit comments