question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

oncreate not firing and actions not updating state with dynamic views

See original GitHub issue

Hello,

I am trying to set up a sort of state-based routing with hyperapp, with the following general architecture to create dynamic views:

const switchView = (state, actions) => {
  if (!state.auth.token) {
    return <Login
      state={state.auth}
      actions={actions.auth}
      />
  }
  if (!state.game.game_id) {
    return <Lobby
      state={state.game}
      actions={actions.game}
      />
  }
}

const view = (state, actions) => (
  <div>
    {switchView(state, actions)}
  </div>
);

app(state, actions, view, document.querySelector('#container'));

Everything on the Login view works as expected, and it switches to the Lobby view as soon as an auth token is attached to state.auth as expected.

Once it reaches the Lobby, view, though, things start to fall apart. oncreate handlers never fire, and although console.logging state and actions shows that all the expected data and functions are present, executing the actions has no effect on the state. I have placed console.logs to determine that the actions are indeed running, they are just not updating state.

Is there something about my architecture that is causing this break? Or is there some other issue?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
okwolfcommented, Jan 20, 2018

@hartbeatnt what you are seeing is expected behavior due to Hyperapp using immutable state updates.

If you wish to log state updates to the console, we do have an official @hyperapp/logger package you might want to try 😊 🔌

1reaction
lukejacksonncommented, Jan 30, 2018

Or if you want to log the state on every update you can do this in the view:

const view = (state, actions) => console.log(state) ||
  <div>
    {switchView(state, actions)}
  </div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

onCreate() gets called when reopen from recent task after ...
Thus it is throwing Exceptions. It seems like the app process is killed when permission is changed and thus Activity is recreated.
Read more >
The activity lifecycle | Android Developers
Your activity does not reside in the Created state. After the onCreate() method finishes execution, the activity enters the Started state, ...
Read more >
Creating and Using Fragments | CodePath Android Cliffnotes
Overview. A fragment is a reusable class implementing a portion of an activity. A Fragment typically defines a part of a user interface....
Read more >
Realtime Database triggers | Cloud Functions for Firebase
When handling a Realtime Database event, the data object returned is a DataSnapshot . For onWrite or onUpdate events, the first parameter is...
Read more >
OnInit - Angular
A lifecycle hook that is called after Angular has initialized all data-bound properties of a directive. Define an ngOnInit() method to handle any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found