26. # This is just a simple example for actioncable server
require 'mobx'
class Todolist
include Mobx::Extension
observable :todos, []
def todo_length
todos.length
end
end
todolist = Todolist.new
runner = Mobx.autorun do
ActionCable.broadcast 'todo_channel', { todos:
todolist.todos, length: todolist.todo_length }
end
todolist.todos << ' '
# > todo_channel
todolist.todos << ' '
# > todo_channel
todolist.todos << ' '
# > todo_channel
28. # This is just a simple example for callback
require 'mobx'
class ModelA
include Mobx::Extension
observable :a, 1
end
class ModelB
def initialize
@b = nil
end
end
a = ModelA.new
b = ModelB.new
Mobx.autorun do
b.b = a.a + 1
b.save!
end
a.a = 2
# b a , callback
30. # This is just a simple example for redis cache
require 'mobx'
class CacheListener
include Mobx::Extension
observable :avatar, '/uploads/xx.jpg'
end
cache = CacheListener.new
runner = Mobx.autorun do
Redis.set(:avatar_key, cache_listener.avatar)
end
cache.avatar = '/uploads/new_avatar.jpg'
# > Cache
31. mobx-ruby
• ( ) -
• ( )
• ( )
• ( ) -
• ( TODO )
• ( TODO )
• ( TODO )
• ( TODO )
• 2018 1