This would really benefit from adding comments in the 'how to use' code samples, or at least using standard foos and baars to make it clear what is user code and what is part of Nothing.js. For example it is not really clear if 'executeAction()' etc are part of Nothing.js. I assumed they were, but then the next sample seems to do property chain traversal transparently, without them.
Show HN: Nothing.js – A chainable mock object which always returns itself
11–20 of 43 posts
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#12 class Whatever; def method_missing *_; self; end; end
Sample usage: irb(main):001:0> Whatever.new.foo.bar.baz - 2
=> #Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#13Ruby equivalent: class Whatever; def method_missing *_; self; end; end Sample usage: irb(main):001:0> Whatever.new.foo.bar.baz - 2 => #
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#14Ruby equivalent: class Whatever; def method_missing *_; self; end; end Sample usage: irb(main):001:0> Whatever.new.foo.bar.baz - 2 => #
Yep, it's way easier to implement in some other languages. Btw, is it callable as well? Can you do Whatever.new().foo.bar().baz with it?
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#15Ruby equivalent: class Whatever; def method_missing *_; self; end; end Sample usage: irb(main):001:0> Whatever.new.foo.bar.baz - 2 => #
Yep, it's way easier to implement in some other languages. Btw, is it callable as well? Can you do Whatever.new().foo.bar().baz with it?
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#16Interesting project, but I'd stick with idx[0] since I have transpilation setup most of the time anyway. Also some of you could be interested in optional.js[1], it's Java's Optional for js, makes it arguably more pleasant to deal with null values, no help for chaining though! [0] https://github.com/facebookincubator/idx [1] https://github.com/JasonStorey/Optional.js
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#17Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#18This is a really neat idea, and is a lot more ergonomic than nulls or optionals in JS. Until optional chaining makes its way into the spec [0], this is the cleanest way I’ve seen to operate on maybe-null values. [0] https://github.com/tc39/proposal-optional-chaining
It's good for unit testing though.
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#19This is a really neat idea, and is a lot more ergonomic than nulls or optionals in JS. Until optional chaining makes its way into the spec [0], this is the cleanest way I’ve seen to operate on maybe-null values. [0] https://github.com/tc39/proposal-optional-chaining
It's also hell to debug as it silently always works and propagate. It's good for unit testing though.
Re: Show HN: Nothing.js – A chainable mock object which always returns itself
#20Earlier quoted context omitted.
Yep, it's way easier to implement in some other languages. Btw, is it callable as well? Can you do Whatever.new().foo.bar().baz with it?
Nope. Ruby doesn’t support the function call paren syntax for anything other than methods. You could do stuff like Whatever.new().foo.().bar[] though.