Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vienna

> 编程语言
Open source

Client-side MVC framework for Opal

181 stars0 likes3 views
WebsiteGitHub

About

Client-side MVC framework for Opal

⚠️ ALERT

The project is no longer actively developed and looking for new maintainers.


Vienna: Client side MVC framework for Opal

Until a better README is out (shame on us) you can take a look at the Opal implementation of TodoMVC.

Installation

Add vienna to your Gemfile with a reference to the Github source.

Note: The vienna hosted on rubygems.org is a different project.

ruby
gem 'opal-vienna'

If you're compiling opal in a static application, make sure to require bundler first.

ruby
require 'bundler'
Bundler.require

Model

Client side models.

ruby
class Book  '2013-1-10')
book.release_date
# => #

Views

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:

xml

  

We can create our view like so:

ruby
class MyView  # [
]

Router

Vienna::Router is a simple router that watches for hashchange events.

ruby
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: 5

Observable

Adds KVO style attribute observing.

ruby
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"

Observable Arrays

ruby
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 2

Todo

  • Support older browsers which do not support onhashchange.
  • Support not-hash style routes with HTML5 routing.

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言