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
Copy file name to clipboardExpand all lines: docs/hyper-model/README.md
+14-8Lines changed: 14 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ In other words, one browser creates, updates, or destroys a Model, and the chang
15
15
16
16
* You access your Model data in your Components, Operations, and Stores just like you would on the server or in an ERB or HAML view file.
17
17
* If an optional push transport is connected Hyperstack broadcasts any changes made to your ActiveRecord models as they are persisted on the server or updated by one of the authorized clients.
18
-
* Some Models can be designated as _server-only_ which means they are not available to the Isomorphic code.
18
+
* Some Models (or even parts of Models) can be designated as _server-only_ which means they are not available to the client code.
19
19
20
20
For example, consider a simple model called `Dictionary` which might be part of Wiktionary type app.
21
21
@@ -38,8 +38,7 @@ class WordOfTheDay < Hyperstack::Component
38
38
39
39
defpick_entry!
40
40
# pick a random word and assign the selected record to entry
# Notice that we use standard ActiveRecord constructs to select our
44
43
# random entry value
45
44
end
@@ -61,7 +60,8 @@ class WordOfTheDay < Hyperstack::Component
61
60
end
62
61
```
63
62
64
-
For complete examples with _push_ updates, see any of the apps in the `examples` directory, or build your own in 5 minutes following one of the quickstart guides:
63
+
**This is the entire code. There are no application APIs needed. The synchronization between server and client is completely taken care of by HyperModel. If you have
64
+
an existing code base little to updates to your existing Models is needed, and you will use the same ActiveRecord API you have been using.**
65
65
66
66
## Isomorphic Models
67
67
@@ -284,7 +284,7 @@ To force the value to be recomputed at the server append a `!` to the end of the
284
284
285
285
`columns_hash`: returns the details of the columns specification. Note that on the server `columns_hash` returns a hash of objects specifying column information. On the client the entire structure is just one big hash of hashes.
286
286
287
-
`abstract_class=`, `abstract_class?`, `primary_key`, `primary_key=`, `inheritance_column`, `inheritance_column=`, `model_name`: All work as on the server. See ActiveRecord documentation for more info.
287
+
`abstract_class=`, `abstract_class?`, `primary_key`, `primary_key=`, `inheritance_column`, `inheritance_column=`, `model_name`, `serialize`, `alias_attribute`, `table_name`: All work as on the server. See ActiveRecord documentation for more info.
288
288
289
289
### Instance Methods
290
290
@@ -313,6 +313,10 @@ end
313
313
314
314
After a save operation completes the models will have an `errors` hash \(just like on the server\) with any validation problems.
315
315
316
+
`save` does not fail, but rather returns `{success: false ...}`. If there was an
317
+
exception the `message` key will hold the error information, otherwise the errors will
318
+
be stored in the records error data (as on the server.)
319
+
316
320
During the save operation the method `saving?` will return `true`. This can be used to instead of \(or with\) the promise to update the screen:
317
321
318
322
```ruby
@@ -333,7 +337,9 @@ end
333
337
334
338
Like `save` destroy returns a promise that is resolved when the destroy completes.
335
339
336
-
After the destroy completes the record's `destroyed?` method will return true.
340
+
After the destroy completes successfully the record's `destroyed?` method will return true.
341
+
342
+
Like `save` destroy never fails, but rather returns `{success: false...}`
337
343
338
344
#### Other Instance Methods
339
345
@@ -391,12 +397,12 @@ The `load` method takes a list of attributes \(symbols\) and will insure these a
391
397
before_mount do
392
398
Todo.find(1).load(:name).then do |name|
393
399
@name= name;
394
-
state.loaded!true
400
+
mutate @loaded=true
395
401
end
396
402
end
397
403
```
398
404
399
-
Think hard about how you are using this, as Hyperstack already acts as flux store, and is managing state for you. It may be you are just creating a redundant store!
405
+
> Think hard about how you are using this, as Hyperstack already acts as flux store, and is managing state for you. It may be you are just creating a redundant store!
Copy file name to clipboardExpand all lines: docs/hyper-state/README.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ The `Hyperstack::State::Observable` module allows you to build classes that shar
9
9
10
10
The easiest way to understand HyperState is by example. If you you did not see the Tic-Tac-Toe example, then **[please review it now](client-dsl/interlude-tic-tac-toe.md)**, as we are going to use this to demonstrate how to use the `Hyperstack::State::Observable` module.
11
11
12
-
In our original TicTacToe implementation the state of the game was stored in the `DisplayGame` component. State was updated by
13
-
"bubbling up" events from lower level components up to `DisplayGame` where the event handers updated the state.
12
+
In our original Tic-Tac-Toe implementation the state of the game was stored in the `DisplayGame` component. State was updated by
13
+
"bubbling up" events from lower level components up to `DisplayGame` where the event handler updated the state.
14
14
15
15
This is a nice simple approach but suffers from two issues:
16
16
+ Each level of lower level components must be responsible for bubbling up the events to the higher component.
@@ -366,7 +366,7 @@ the appropriate `mutate` or `observe` method.
366
366
Typically in a large system you will have one or more central stores, and what you end up passing as parameters are either instances of those stores, or some other kind of index into the store. Or if (as in the case of our Game) there is only one store, you
367
367
need not pass any parameters at all.
368
368
369
-
We can rewrite the last iteration of DisplayBoard to demonstrate this:
369
+
We can rewrite the previous iteration of `DisplayBoard` to demonstrate this:
370
370
371
371
```ruby
372
372
classDisplaySquare
@@ -391,7 +391,7 @@ Here `DisplayBoard` no longer takes any parameter (and should be renamed again t
391
391
`DisplaySquare` takes the id of the square to display, but the game or the current board are never passed as parameters;
392
392
there is no need to as they are implicit.
393
393
394
-
Whether to not passstore objects, an instance of a store, and index into the store is a design decision that depends on
394
+
Whether to pass (or not pass) a store class, an instance of a store, or some other index into the store is a design decision that depends on
395
395
lots of factors, mainly how you see your application evolving over time.
0 commit comments