-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback class #3
base: master
Are you sure you want to change the base?
Conversation
Nice! Can you squash the commits please? |
Mh, I already have a spike on class implementation for My attempt is different, though. WDYT? |
Replicate on_proc test for On::Class. Implement empty On::Class. Fix test, use build instead of new. Add build-pattern to On::Class. Implement class wrapper for On. Update On::Class' inline documentation.
Squashed! I dont think those to features are similar. Your class implementation is for the caller, so he can encapsulate the callback-block into a class. My class implementation is for encapsulating the callback-triggering of the callee. Don't you thing both features are neat? :) |
Well, it depends. My solution encourages you to create "callback" classes a la: class MyCallback
include On::Class
def on_success
...
end
end Your solution seems to be "just" a syntatic sugar on how to create class MyCallback < On::Class::CallbackClass
callbacks :success
end But I don't see the point of doing the above. Can you explain? Yes, these are different features. We have to name them distinctly :) |
class UserCreating
Callback = On::Class.build(:success, :failure)
Response = Struct.new(:user_id)
def initialize(user_name)
@user_name = user_name
end
def create(&block)
back = Callback.new(&block)
user = user_repo.create(:user_name => @user_name)
if user
back.call :success, Response.new(user.id)
else
back.call :failure
end
end
end
class Call
include On::Class
def on_success(response)
p :id => response.user_id
end
def on_failure
# :(
end
end
UserCreating.new('peter').create(&(Call.new)) Despite the naming-clash, those are the two usecases combined. I thought about this Class-implementation, because it cleans up the usecase action-method. If you want to, I can name |
Ok, got it. Good example! Sadly, I'd like to see class UserCreating
Callback = On::Callback.create(:success, :failure)
# or
Callback = On.callback(:succes, :failure)
... My approch in |
Agreed! A Class named If I think it true, even Perhaps the feature could be embedded into Callback = On.create(:success, :failure)
# or
Callback = On.to_class(:success, :failure)
|
Mh Callback = On.create(:success, :failure)
# or
Callback = On.to_class(:success, :failure) reads kind of ugly, isn't :/ @holderbaum enable your naming-power. NOW!! :) |
NAMINGPOWER ENABLED 👊 Callback = On::Back.new(:success, :failure)
# this one is still my favourite:
Callback = On::Callback.new(:success, :failure) Is there any Chance, we can rename the innerclass |
:)Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet. Jakob Holderbaum notifications@github.com schrieb: NAMINGPOWER ENABLED Callback = On::Back.new(:success, :failure) # this one is still my favourite: Callback = On::Callback.new(:success, :failure) Is there any Chance, we can rename the innerclass Callback? — |
This optional addon allows creation of a semi-static callback-class. It's kind of semantic sugar.