Live data from Hacker News

Show HN: Nothing.js – A chainable mock object which always returns itself

github.com

11–20 of 43 posts

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#11

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.

I agree, examples can be (and will be) improved with additional comments.

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#13
post #12

Ruby 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

#14
post #13
post #12

Ruby 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?

`.foo.bar` are method calls (parenses are optional in Ruby)

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#15
post #13
post #12

Ruby 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?

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.

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#16

Interesting 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

And if you’re using TypeScript, theres also TSOption https://www.npmjs.com/package/tsoption

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#17
This 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

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#18
post #17

This 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

#19
post #17

This 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.

That’s true, but ostensibly you only use it in places where you expect nulls and don’t intend to debug anything. That’s why Smalltalk, C#, CoffeeScript, and probably JS and TS soon have null chaining.

Re: Show HN: Nothing.js – A chainable mock object which always returns itself

#20
post #15
post #13

Earlier 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.

foo, bar, and baz are all methods here, so you can use parens.
Post reply on HN