Client-side MVC framework for Opal
The project is no longer actively developed and looking for new maintainers.
Until a better README is out (shame on us) you can take a look at the Opal implementation of TodoMVC.
Add vienna to your Gemfile with a reference to the Github source.
Note: The vienna hosted on rubygems.org is a different project.
gem 'opal-vienna'If you're compiling opal in a static application, make sure to require bundler first.
require 'bundler'
Bundler.requireClient side models.
class Book '2013-1-10')
book.release_date
# => #Vienna::View is a simple wrapper class around a dom element representing a
view of some model (or models). A view's element is dynamically created when
first accessed. View.element can be used to specify a dom selector to find
the view in the dom.
Assuming the given html:
We can create our view like so:
class MyView # [
]Vienna::Router is a simple router that watches for hashchange events.
router = Vienna::Router.new
router.route("/users") do
puts "need to show all users"
end
router.route("/users/:id") do |params|
puts "need to show user: #{ params[:id] }"
end
# visit "example.com/#/users"
# visit "example.com/#/users/3"
# visit "example.com/#/users/5"
# => "need to show all users"
# => need to show user: 3
# => need to show user: 5Adds KVO style attribute observing.
class MyObject
include Vienna::Observable
attr_accessor :name
attr_reader :age
def age=(age)
@age = age + 10
end
end
obj = MyObject.new
obj.add_observer(:name) { |new_val| puts "name changed to #{new_val}" }
obj.add_observer(:age) { |new_age| puts "age changed to #{new_age}" }
obj.name = "bob"
obj.age = 42
# => "name changed to bob"
# => "age changed to 52"class MyArray
include Vienna::ObservableArray
end
array = MyArray.new
array.add_observer(:content) { |content| puts "content is now #{content}" }
array.add_observer(:size) { |size| puts "size is now #{size}" }
array content is now [:foo]
# => size is now 1
# => content is now [:bar]
# => size is now 2MIT
No open issues yet, or sync has not completed.