This repository was archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
What is HyperLoop
Mitch VanDuyn edited this page Jan 6, 2017
·
2 revisions
@catmando
Ruby HyperLoop is a client application framework based on React.js with a unique combination of features:
- Ruby is used throughout both on the client and on the server.
- Server side ActiveRecord models are automatically accessible on the client code.
- Complex operations are encapsulated as Actions which can run on the client, server or both.
- Client-Server communication is automatically and transparently handled by the framework.
- Integrates easily with existing React.js libraries and components
- Integrates easily with existing Rails applications
The goal of HyperLoop is to allow the developer to write code that is directed toward solving the user's needs in the most straight forward manner, without redundant code, and unnecessary APIs.
Here is a slice of an example application:
class BookList < React::Component::Base
# Display each book in our catalog unless its already in the cart basket.
# When the user clicks on a book, add it the Basket.
render(UL) do
Book.all.each do |book|
LI { "Add #{book.name}" }.on(:click) do
AddBookToBasket(book: book) do |outcome|
alert "Failed to add the book" unless outcome.success?
end
end unless acting_user.basket.include? book
end
end
end
class AddBookToBasket < HyperLoop::Action
# Add a book to the basket
# Send the user more info about the book via email.
param :book, type: Book
def execute
acting_user.basket << book
EmailUserAboutBook(book: params.book, user: acting_user)
end
end
class EmailUserAboutBook < HyperLoop::ServerAction
allow_operation { acting_user }
param :book, type: Book
param :user, type: User
def execute
return if params.user.watch_list.include? params.book
UserMailer.book_email(params.user, params.book)
end
end
This is a complete example with the only things not shown are the definition of the UserMailer
and the ActiveRecord models.
A quick look at the code shows the power of HyperLoop
- Everything is written in Ruby.
- Our
BookList
is a Ruby Class that generates our HTML using React.js. -
BookList
directly scopes the ARBook
model and accesses its attributes and relationships. - Adding a book to the basket will automatically re-render the book list.
- The relationship between the html output and the action is clear.
- Externally there no difference between an action executing on the server or the client.
- While this code will continuously move data between the server and client there is no APIs or even controllers needed.
- Security is enforced through policy regulations like
allow_operation
which can be applied to models as well as actions.