Skip to content

Commit 8af04f7

Browse files
Merge branch 'edge' of https://github.com/hyperstack-org/hyperstack into edge
2 parents cd963f2 + 3bbfb6e commit 8af04f7

File tree

341 files changed

+10665
-4394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

341 files changed

+10665
-4394
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
- COMPONENT=hyper-react LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
2525
- COMPONENT=hyper-router LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
2626
- COMPONENT=hyper-spec LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
27+
- COMPONENT=hyper-state LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
2728
- COMPONENT=hyper-store LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
2829
- COMPONENT=hyper-trace LANGUAGE=ruby LANGUAGE_VERSION=2.5.1
2930
- COMPONENT=hyperloop LANGUAGE=ruby LANGUAGE_VERSION=2.5.1

current-status.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
### Current Status: Working towards 0.1 release. See Roadmap for details.
2+
3+
4+
[![Build Status](https://travis-ci.org/hyperstack-org/hyperstack.svg?branch=edge)](https://travis-ci.org/hyperstack-org/hyperstack)
5+
6+
`hyperstack-config`, `hyper-store`, and `hyper-component` are now following the public interface conventions.
7+
8+
I.e. to create a component you now do this:
9+
10+
```ruby
11+
class MyComponent
12+
include Hyperstack::Component
13+
...
14+
end
15+
```
16+
17+
The philosophy is that you will probably have a base class defined like this:
18+
19+
```ruby
20+
class HyperComponent
21+
include Hyperstack::Component
22+
end
23+
```
24+
25+
Which you can then inherit from.
26+
27+
The bigger change is that the state mechanism has now been greatly simplified, but you can choose when to move
28+
into the future by your choice of which module to include:
29+
30+
```ruby
31+
class HyperComponent
32+
include Hyperstack::Component
33+
# to use the current state/store syntax in your components:
34+
include Hyperstack::Legacy::Store
35+
end
36+
37+
class HyperStore
38+
# to use the legacy state store syntax in your stores:
39+
include Hyperstack::Legacy::Store
40+
end
41+
```
42+
43+
To use the new hotness change the includes:
44+
45+
```ruby
46+
class HyperComponent
47+
include Hyperstack::Component
48+
# to use the current state/store syntax in your components:
49+
include Hyperstack::State::Observable
50+
end
51+
52+
class HyperStore
53+
# to use the legacy state store syntax in your stores:
54+
include Hyperstack::State::Observable
55+
end
56+
```
57+
58+
In summary you will need to update your hyperloop/hyperstack components and store folders to have `hyper_component.rb`
59+
and `hyper_store.rb` files. And then update your components and stores to reference your application defined `HyperComponent`
60+
and `HyperStore` classes.
61+
62+
### The new world of state:
63+
64+
Its great, its exciting, and its sooo much easier:
65+
66+
Each ruby object has *state*, defined by its instance variables. Hyperstack does not define *any new state concepts*. From
67+
now on you just use instance variables in your components and other objects as you normally would.
68+
69+
The one caveat is that you have to *tell* the system when you are *mutating* state, and when some external entity is
70+
*observing* your state.
71+
72+
The `Hyperstack::State::Observable` module provides a handful of methods to make this very easy.
73+
74+
Here is an example (compare to the state example on the [Hyperstack.org home page](https://hyperstack.org/))
75+
76+
```ruby
77+
class UsingState < HyperComponent
78+
79+
# Our component has two instance variables to keep track of what is going on
80+
# @show - if true we will show an input box, otherwise the box is hidden
81+
# @input_value - tracks what the user is typing into the input box.
82+
# We use the mutate method to signal all observers when the state changes.
83+
84+
render(DIV) do
85+
# the button method returns an HTML element
86+
# .on(:click) is an event handeler
87+
button.on(:click) { mutate @show = !@show }
88+
DIV do
89+
input
90+
output
91+
easter_egg
92+
end if @show
93+
end
94+
95+
def button
96+
BUTTON(class: 'ui primary button') do
97+
@show ? 'Hide' : 'Show'
98+
end
99+
end
100+
101+
def input
102+
DIV(class: 'ui input fluid block') do
103+
INPUT(type: :text).on(:change) do |evt|
104+
# we are updating the value per keypress
105+
mutate @input_value = evt.target.value
106+
end
107+
end
108+
end
109+
110+
def output
111+
# this will re-render whenever input_value changes
112+
P { "#{@input_value}" }
113+
end
114+
115+
def easter_egg
116+
H2 {'you found it!'} if @input_value == 'egg'
117+
end
118+
end
119+
```
120+
121+
So to make our instance variables work with components we just need to call `mutate` when the state changes.
122+
123+
Here is a very simple store that is just a global click counter
124+
125+
```ruby
126+
class Click
127+
include Hyperstack::State::Observable
128+
class << self
129+
def count
130+
observe @count ||= 0
131+
end
132+
def inc
133+
mutate @count = count + 1
134+
end
135+
def count=(x)
136+
mutate @count = x
137+
end
138+
def reset
139+
mutate @count = 0
140+
end
141+
end
142+
end
143+
```
144+
145+
Now any component can access and change the counter by calling `Click.count`, `Click.inc` and `Click.reset` as needed.
146+
147+
The `observe` and `mutate` methods take no params (handy for adding to the end of a method), a single param as shown above,
148+
or a block in which case the entire block will be executed before signaling the rest of the system.
149+
150+
That is all there is to it, but to make things easier `Observable` contains some other helper methods which we can use:
151+
152+
```ruby
153+
class Click
154+
include Hyperstack::State::Observable
155+
class << self
156+
observer(:count) { @count ||= 0 }
157+
state_writer :count
158+
mutator(:inc) { count = count + 1 }
159+
mutator(:reset) { count = 0 }
160+
end
161+
end
162+
```
163+
164+
The `observer` and `mutator` methods create a method wrapped in `observe` or `mutate` block.
165+
166+
In addition there are `state_accessor`, `state_reader` and `state_writer` methods that work just like `attr_accessor` methods
167+
except access is wrapped in the appropriate `mutate` or `observe` method.
168+
169+
The methods can be used either at the class or instance level as needed.
170+
171+
Because stateful components use the same `Observable` module all the above methods are available to help structure your
172+
components nicely.
173+
174+
Notice in the component example we never use `observe` that is because by definition components always `observe` their own
175+
state automatically so you don't need to.
176+

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Hyperstack
22

3-
[![Build Status](https://travis-ci.org/hyperstack-org/hyperstack.svg?branch=edge)](https://travis-ci.org/hyperstack-org/hyperstack)
3+
This is the edge branch - for current status on development see [current status.](https://github.com/hyperstack-org/hyperstack/blob/edge/current-status.md)
4+
5+
Visit the legacy branch for the current stable and released Hyperloop (old name) system. [![Build Status](https://travis-ci.org/hyperstack-org/hyperstack.svg?branch=hyperloop-legacy)](https://travis-ci.org/hyperstack-org/hyperstack)
46

57
Hyperstack is a Ruby-based DSL and modern web toolkit for building spectacular, interactive web applications fast!
68

ruby/hyper-component/CHANGELOG.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file starting with v0.8.6.
4+
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5+
6+
Changes are grouped as follows:
7+
- **Added** for new features.
8+
- **Changed** for changes in existing functionality.
9+
- **Deprecated** for once-stable features to be removed in upcoming releases.
10+
- **Removed** for deprecated features removed in this release.
11+
- **Fixed** for any bug fixes.
12+
- **Security** to invite users to upgrade in case of vulnerabilities.
13+
14+
<!--
15+
Whitespace conventions:
16+
- 4 spaces before ## titles
17+
- 2 spaces before ### titles
18+
- 1 spaces before normal text
19+
-->
20+
21+
## [0.12.0] - Unreleased
22+
23+
### Added
24+
25+
- `React::Server` is provided as a module wrapping the original `ReactDOMServer` API, require `react/server` to use it. (#186)
26+
- `React::Config` is introduced, `environment` is the only config option provided for now. See [#204](https://github.com/ruby-hyperloop/hyper-react/issues/204) for usage details.
27+
28+
### Changed
29+
30+
- State syntax is now consistent with Hyperloop::Store, old syntax is deprecated. (#209, #97)
31+
32+
### Deprecated
33+
34+
- Current ref callback behavior is deprecated. Require `"react/ref_callback"` to get the updated behavior. (#188)
35+
- `Hyperstack::Component::ReactAPI.render_to_string` & `Hyperstack::Component::ReactAPI.render_to_static_markup` is deprecated, use `React::Server.render_to_string` & `React::Server.render_to_static_markup` instead. (#186)
36+
- `react/react-source` is deprecated, use `react/react-source-browser` or `react/react-source-server` instead. For most usecase, `react/react-source-browser` is sufficient. If you are using the built-in server side rendering feature, the actual `ReactDOMServer` is already provided by the `react-rails` gem. Therefore, unless you are building a custom server side rendering mechanism, it's not suggested to use `react/react-source-server` in browser code. (#186)
37+
38+
### Removed
39+
40+
- `react-latest` & `react-v1x` is removed. Use `react/react-source-browser` or `react/react-source-server` instead.
41+
- Support for Ruby < 2.0 is removed. (#201)
42+
43+
### Fixed
44+
45+
- [NativeLibrary] Passing native JS object as props will raise exception. (#195)
46+
- Returns better error message if result of rendering block is not suitable (#207)
47+
- Batch all state changes and execute *after* rendering cycle (#206, #178) (Code is now moved to Hyper::Store)
48+
You can revert to the old behavior by defining the `React::State::ALWAYS_UPDATE_STATE_AFTER_RENDER = false`
49+
- Memory Leak in render context fixed (#192)
50+
51+
52+
## [0.11.0] - 2016-12-13
53+
54+
### Changed
55+
56+
- The whole opal-activesuppport is not loaded by default now. This gave us about 18% size reduction on the built file. If your code rely on any of the module which is not required by hyper-react, you need to require it yourself. (#135)
57+
58+
### Deprecated
59+
60+
- Current `Hyperstack::Component::ReactAPI.render` behavior is deprecated. Require `"react/top_level_render"` to get the updated behavior. (#187)
61+
- `React.is_valid_element` is deprecated in favor of `Hyperstack::Component::ReactAPI.is_valid_element?`.
62+
- `expect(component).to render('<div />')` is now deprecated in favor of `expect(component).to render_static_html('<div />')`, which is much clearer.
63+
64+
### Fixed
65+
66+
- `ReferenceError: window is not defined` error in prerender context with react-rails v1.10.0. (#196)
67+
- State might not be updated using `React::Observable` from a param. (#175)
68+
- Arity checking failed for `_react_param_conversion` & `React::Element#initialize` (#167)
69+
70+
71+
## [0.10.0] - 2016-10-30
72+
73+
### Changed
74+
75+
- This gem is now renamed to `hyper-react`, see [UPGRADING](UPGRADING.md) for details.
76+
77+
### Fixed
78+
79+
- ReactJS functional stateless component could not be imported from `NativeLibrary`. Note that functional component is only supported in React v14+. (#162)
80+
- Prerender log got accumulated between reqeusts. (#176)
81+
82+
## [0.9.0] - 2016-10-19
83+
84+
### Added
85+
86+
- `react/react-source` is the suggested way to include ReactJS sources now. Simply require `react/react-source` immediately before the `require "reactrb"` in your Opal code will make it work.
87+
88+
### Deprecated
89+
90+
- `react-latest` & `react-v1x` is deprecated. Use `react/react-source` instead.
91+
92+
### Removed
93+
94+
- `opal-browser` is removed from runtime dependency. (#133) You will have to add `gem 'opal-browser'` to your gemfile (recommended) or remove all references to opal-browser from your manifest files.
95+
96+
### Fixed
97+
98+
- `$window#on` in `opal-jquery` is broken. (#166)
99+
- `Element#render` trigger unnecessary re-mounts when called multiple times. (#170)
100+
- Gets rid of react warnings about updating state during render (#155)
101+
- Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
102+
- Don't send nil (null) to form components as the value string (#157)
103+
- Process `params` (props) correctly when using `Element#on` or `Element#render` (#158)
104+
- Deprecate shallow param compare (#156)
105+
106+
107+
## [0.8.8] - 2016-07-13
108+
109+
### Added
110+
111+
- More helpful error messages on render failures (#152)
112+
- `Element#on('<my_event_name>')` subscribes to `my_event_name` (#153)
113+
114+
### Changed
115+
116+
- `Element#on(:event)` subscribes to `on_event` for reactrb components and `onEvent` for native components. (#153)
117+
118+
### Deprecated
119+
120+
- `Element#on(:event)` subscription to `_onEvent` is deprecated. Once you have changed params named `_on...` to `on_...` you can `require 'reactrb/new-event-name-convention.rb'` to avoid spurious react warning messages. (#153)
121+
122+
123+
### Fixed
124+
125+
- The `Element['#container'].render...` method generates a spurious react error (#154)
126+
127+
128+
129+
130+
## [0.8.7] - 2016-07-08
131+
132+
133+
### Fixed
134+
135+
- Opal 0.10.x compatibility
136+
137+
138+
## [0.8.6] - 2016-06-30
139+
140+
141+
### Fixed
142+
143+
- Method missing within a component was being reported as `incorrect const name` (#151)

0 commit comments

Comments
 (0)