HNHacker News
TopNewBestAskShowJobs

slmgc

63 karma · joined August 27, 2017

submissionscomments
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
Updated the readme, added a few comments, changed some names
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
Added a FAQ section: https://github.com/slmgc/Nothing#faq
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
Wrapping you code into a try/catch block decreases performance even more, you don't want to do that. You might want to check it out: https://github.com/GoogleChrome/proxy-polyfill
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
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?
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
I agree, examples can be (and will be) improved with additional comments.
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
I've seen this one: https://github.com/GoogleChrome/proxy-polyfill
slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
idx requires a transpilation step.

> you try to access a property on a value that's null (which you think isn't null), and instead of getting an error, nothing happens

You can check for Nothing if you know you shouldn't get one. It's not about swallowing errors, it's about removing try/catch and all this `a && a.b && a.b.c && a.b.c()` boilerplate code.

> Optional chaining[2] would add this to JS at the language level by using ?. as the operator

But it's not there yet and it will require a transpilation step for quite some time before all the major browsers will introduce this feature.

Nothing returns "safe" default values instead of null/undefined, which might come in useful in some cases. Also, it can be used in unit tests to mock some deeply-nested constructs.

slmgc··on Show HN: Nothing.js – A chainable mock object which always returns itself
Nope, hint won't help here as it gets `default` instead of `number`.
slmgc··on Show HN: React-hint – 150LoC Tooltip Component for React, Preact and Inferno
Yep, it works just fine without Preact's compatibility layer:

  import {h, Component} from 'preact'
  import {ReactHintFactory} from 'react-hint'
  import 'react-hint/css/index.css'

  const ReactHint = ReactHintFactory({createElement: h, 
  Component})
slmgc··on Show HN: React-hint – 150LoC Tooltip Component for React, Preact and Inferno
I made this library a while ago, long before all this hype about React's license (which was with the questionable clause from the beginning). I added support for Preact as I liked the minimalistic style of Preact, used it in my own projects and Jason was really responsive solving Preact's compatibility issues. Later on, Dominic asked if I want to add support for Inferno, which I did. I really love that there are different library implementations with compatible API, so you can choose a proper solution based on its pros/cons.
slmgc··on Show HN: React-hint – 150LoC Tooltip Component for React, Preact and Inferno
Nope, it's a pure coincidence as I've made the button style just to record the GIF. As for the tooltip itself, it uses a generic style, but thanks for the link to your project, looks nice :)
slmgc··on Show HN: React-hint – 150LoC Tooltip Component for React, Preact and Inferno
That's a good question, thanks! I didn't think about that, but, surely, this functionality should be added. I will try to research what would be the best solution for accessibility.