CrSignals is a signals/slots library. You can define your signal/slot function, wire them and emit data.
-
Add the dependency to your
shard.yml
:dependencies: CrSignals: github: firejox/CrSignals
-
Run
shards install
- Here is a basic example of CrSignals library.
require "CrSignals"
class Foo
include CrSignals::Generator
property x : Int32 = 0
cr_signal value_change(Int32)
def set_x(v : Int32)
if @x != v
@x = v
value_change(v)
end
end
end
a = Foo.new
b = Foo.new
a.connect_value_change(->b.set_x(Int32))
a.set_x(3)
puts b.x # => 3
a.disconnect_value_change(->b.set_x(Int32))
a.set_x(4)
puts b.x # => 3
- If you operate with incorrect type, it will report a compile error.
require "CrSignals"
class Foo
include CrSignals::Generator
property x : Int32 = 0
cr_signal value_change(Int32)
def set_x(v : Float64); end
end
a = Foo.new
b = Foo.new
a.connect_value_change(->b.set_x(Float64)) # compile error
- Fork it (https://github.com/firejox/CrSignals/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Firejox - creator and maintainer