Beta
Callback Set
14wthit56
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
The actual tests are seriously lacking, even a half-working solution will have a great chance to pass given some minimal fiddling.
Also, needs random tests.
Okay. Could you post a code block of an example of a non-solution, please, so I can get some ideas on what the problem is?
Needs sample tests
I can't make heads or tails of this description. What's the original
callback
, how's it different from ones added by theadd
method, why doesadd
return a trigger function but there's no trigger function for the original callback, isinstance.count
supposed to start at 0 and count the originalcallback
plus each callback that youadd
, then count down each time a callback is triggered? And if you callresolve()
then do the callbacks get triggered or not? The description just says the originaloncomplete
gets triggered, which was the originalcallback
.And as I see it,
count
should be a getter for a private value that can't be changed outside of the class methods.instance.count = x
should either throw an error or simply have no effect, becausecount
is supposed to be counting something, and it should remain the correct count always.Code examples would help immensely, too.
I've now added code examples. Hopefully they'll help others to figure things out.
On your specific points:
I have made some changes to the description to try to make these things a little clearer. I hope my explanation above has helped you, though?
Okay, it's clearer now. The sample code you added to the description has
CallbackSet
which should beCreateCallbackSet
but other than that it's pretty good.Do you have any tests that check to see if the callback functions are executed within the correct context?
e.g.
If the callback functions aren't run from their original context,
secret
will be undefined.Great stuff. And typo fixed--thanks for that.
I think you mean "closure"? And closures are implicitly preserved; there's no way of running a function without it's original closure, as the closure is lumped in with a function when it is created.
You're right. I guess there could be problems if the functions referred to
this
but I'm not coming up with any easy examples.The thing is, unless the API supports it (and this one doesn't), there is no way of guaranteeing a callback will have a particular context. So most callbacks just don't use a context, anyway.