avdi / brainguy Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi Avdi,
I was doing some research about this gem and I've found unexpected behavior when using the on
shortcut syntax. I've expected full event as the block argument but I got only event explicit arguments (see the exampel below).
If this behavior is intentional what was decision behind it?
require 'brainguy'
class BrainguyWorker
include Brainguy::Observable
def call(name)
emit(:call_success, "Called #{name}")
end
end
class BrainguyListener
include Brainguy::Observer
def on_call_success(event)
puts "Listener: #{event.inspect}"
end
end
brain = BrainguyWorker.new
brain.events.attach BrainguyListener.new
listener = proc do |event|
puts "Proc: #{event.inspect}"
end
brain.on(:call_success) do |event|
puts "Block: #{event.inspect}"
end
# Output:
# Listener: #<struct Brainguy::Event name=:call_success,... args=["Called Blurb"]>
# Proc: #<struct Brainguy::Event name=:call_success,... args=["Called Blurb"]>
# Block: "Called Blurb"
First of all, thanks for taking the time to build this library. It's really neat and I really appreciate all effort you've put in.
Recently, I've done some work in Java using RxJava. It's a Java implementation of ReactiveX. They have named the cancellation of a subsctiption, unsubscribe
. I've seen this naming for a few other libraries as well.
Naturally, I fiddled around with brainguy and tried to call #unsubscribe
on the subscription. But it didn't work since it's called #cancel
. I was wondering what you think about creating an alias, #unsubscribe
for Subscription#cancel
? It could be a nice win for others assuming the same API as with other Observer implementations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.