Dictionary
which might be part of Wiktionary type app.hyperstack/models
folder. Only models in this folder will be seen by Hyperstack and compiled to Javascript. Once a Model is on this folder it ill be accessable to both your client and server code.app\models
app\hyperstack\models
DummyValue
s) are displayed, and when they do get loaded, those parts of the display will re-render.Todo.all
will have no action, but Todo.all.pluck[:title]
will return an array of titles.new
: Takes a hash of attributes and initializes a new unsaved record. The values of any attributes not specified in the hash will be taken from the Models default values specified in the data base schema.new
is passed a native javascript object it will be treated as a hash and converted accordingly.create
: Short hand for new(...).save
. See the save
instance method for details on how saving is done.scope
and default_scope
: Hyperstack adds four new options to these methods: joins
, client
, select
and server
. The joins
option provides information on how the scope will be joined with other models. The client
and select
options allow scoping to be done on the client side to offload this from the server, and the server
option is there just for symmetry with the other options.unscoped
and all
: These builtin scopes work just like standard ActiveRecord.all
: Models will respond like enumerators.where
: The where method can be used to filter records:Thewhere
method is implemented internally as a scope on the client that will execute the where method on the server. If the parameters to the where method the scope will be updated on the client, but using SQL in the where as in the above example will get executed on the server.
find
: takes an id and delivers the corresponding record.find_by
: takes a single item hash indicating an attribute value pair to find.find_by_...
: i.e. find_by_first_name
these methods will find the first record with a matching attribute.limit
and offset
: These builtin scopes behave as they do on the server:belongs_to, has_many, has_one
: These all work as on the server. However it is important that you fully specify both sides of the relationship.composed_of
: You can create aggregate models like ActiveRecord.server_method
macro:!
to the end of the name, otherwise the last value returned from the server will continue to be returned.column_names
: returns a list of the database columns.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.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.belongs_to
relationships also have a setter. has_many
relationships can be updated using the push (<<
) operator or using the delete
method.save
method works like ActiveRecord save, except it returns a promise that is resolved when the save completes (or fails.)errors
hash (just like on the server) with any validation problems.saving?
will return true
. This can be used to instead of (or with) the promise to update the screen:save
destroy returns a promise that is resolved when the destroy completes.destroyed?
method will return true.new?
returns true if the model is new and not yet saved.primary_key
returns the primary key for the modelid
returns the value of the primary key for this instancemodel_name
returns the model_name.revert
Undoes any unsaved changes to the instance.changed?
returns true if any attributes have changed (always true for a new model)dup
duplicate the instance.==
two instances are the same if it is known that they reference the same underlying table row...._changed?
(i.e. name_changed?) returns true if the specific attribute has changed.itself
returns the record, but will override lazy loading and force a load of at least the model's id.loaded?
or loading?
method to determine if the object represents a real loaded value or not. Any value for which loaded?
returns false
(or loading?
returns true
) will eventually load and cause a re-renderHyperstack::Model.load
method:load
method takes a list of attributes (symbols) and will insure these are loaded. Load returns a promise that is resolved when the load completes, or can be passed a block that will execute when the load completes.scope
and default_scope
macros. Note you must use the scope
macro (and not class methods) for things to work with Hyperstack.:joins
, :client
, and :select
options.:joins
option tells the Hyperstack client which models are joined with the scope. You must add a :joins
option if the scope has any data base join operations in it, otherwise if a joined model changes, Hyperstack will not know to update the scope.:client
and :select
options provide the client a way to update scopes without having to contact the server. Unlike the :joins
option this is an optimization and is not required for scopes to work.action_cable
js file is required in your assets.app/assets/javascripts/application.js
will finish with a require_tree .
and this will pull in the cable.js
file which will pull in action_cable.js
application.js
simply does a require action_cable
that will be sufficient for Hyperstack.gem 'pusher'
to your Gemfile.gem 'pusher'
to your Gemfile.gem 'pusher-fake'
to the development and test sections of your Gemfile.localhost:3000/Hyperstack/console
rr
to wherever you are mounting Hyperstack in your routes file.session.id
and current acting_user
which you will need, plus some helper methods to reduce typingchannels(session_id = session.id, user = acting_user)
e.g. channels
returns all channels connecting to this session and user providing nil as the acting_user will test if connections can be made without there being a logged in user.can_connect?(channel, user = acting_user)
e.g. can_connect? Todo
returns true if current acting_user can connect to the Todo class. You can also provide the class name as a string.can_connect?(channel, user = acting_user)
e.g. can_connect? Todo.first
returns true if current acting_user can connect to the first Todo Model. You can also provide the instance in the form 'Todo-123'viewable_attributes(instance, user = acting_user)
view_permitted?(instance, attribute, user = acting_user)
create_permitted?(instance, user = acting_user)
e.g. create_permitted?(Todo.new, nil)
can anybody save a new todo? e.g. destroy_permitted?(Todo.last)
can the acting_user destroy the last TodoTodo.new.save
will broadcast the changes to the Todo Model to any authorized channels.ApplicationPolicy
class.require pusher
in application.js file this results in an error like this:require 'pusher'
in your application.js file if using pusher. DO NOT require pusher from your components manifest as this will cause prerendering to fail.allow_change(to: :all, on: [:create, :update, :destroy]) { true }
config.action_cable.allowed_request_origins
includes the url you use for development (including the port) and that you are using Puma
.Hyperstack/models
so it can find all the column information for all Isomorphic models.couldn't find file 'browser'
The hyper-component
v0.10.0 gem removed the dependency on opal-browser. You will have to add the 'opal-browser' gem to your Gemfile.DummyValue
You are still have the old reactive-record
gem in your Gemfile, remove it from your gemfile and your components manifest.session
for nil
You are still referencing the old reactive-ruby or reactrb gems either directly or indirectly though a gem like reactrb-router. Replace any gems like reactrb-router
with hyper-router
. You can also just remove reactrb
, as hyper-model
will be included by the hyper-model
gem.WebSocket connection to 'ws://localhost:3000/cable' failed: WebSocket is closed before the connection is established.
every few seconds in the console. There are probably lots of reasons for this, but it means ActionCable can't get itself going. One reason is that you are trying to run with Passenger instead of Puma, and trying to use async
mode in cable.yml file. async
mode requires Puma.