okwolf / hyperapp-logger

Log Hyperapp state updates and action information to the console.
MIT License
47 stars 5 forks source link

Cannot read property 'parentNode' of undefined #26

Closed vladyn closed 4 years ago

vladyn commented 4 years ago

Hello there, I'm constantly getting the above Error passing any of the view of my app. I'm invoking the logger from a class constructor:

withLogger(app)(state, actions, this.views.intro(state), document.body);

And yes, this come from the hyperapp in the render function, but indeed the node of the view is undefined. Anybody having an idea what I'm doing wrong?

zaceno commented 4 years ago

I suspect you are using hyperapp v2, whereas this logger (judging by the signature) is for hyperapp v1.

vladyn commented 4 years ago

I suspect you are using hyperapp v2, whereas this logger (judging by the signature) is for hyperapp v1.

Oh my, you're absolutely right! Good catch! Did you had any previous experience with similar tool for logging the state and actions in HP2?

zaceno commented 4 years ago

THere is: https://github.com/mrozbarry/hyperapp-debug It may still be under development though. Haven't checked it recently. Perhaps @okwolf is planning a v2 version of the logger?

Personally I usually just hook in to the middleware. Unfortunately there aren't docs for it yet, but basically:

app({
  ...
  middleware: originalDispatch => (action, data) => {
    if (typeof action !== 'function' && (
       !Array.isArray(action) ||
           !Array.isArray(action[0])
    ) console.log('New state', action) 
    return originalDispatch(action, data)
  }
})

...or something like that. Just typed it off the top of my head and didn't test it

vladyn commented 4 years ago

Personally, I usually just hook in to the middleware. Unfortunately, there aren't docs for it yet, but basically:

... a perfect shot from the top of your head - works like a charm! I've added some console.group along with console.dir for good looking - thank you!

okwolf commented 4 years ago

I hadn't been planning an update to the logger, but I might consider it.