goatslacker/alt

Child components fail when using Render.withData

Open

#354 opened on Jun 25, 2015

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (3,451 stars) (337 forks)batch import
bughelp wanted

Description

Failing test case:

import Alt from 'alt'
import * as Render from 'alt/utils/Render'

const alt = new Alt()

import React, { Component } from 'react'

const actions = alt.generateActions('success', 'fail')

const Source = {
  things: {
    remote(_, x) {
      return Promise.resolve(x)
    },

    success: actions.success,
    error: actions.fail
  }
}

const store = alt.createStore(class {
  constructor() {
    this.registerAsync(Source)
    this.bindActions(actions)

    this.caca = null
  }

  success(x) {
    console.log('ok')
    this.caca = x
  }

  fail() {
    console.log('shit')
  }
}, 'store')


const App = Render.withData(() => {
  return store.things(1)
}, class extends Component {
  static displayName = 'App'

  constructor() {
    super()
    console.log(1)
  }

  render() {
    console.log('RENDERING')
    return (
      <div>
        <div>Hello World {store.getState().caca}</div>
        <Child />
      </div>
    )
  }
})

const Child = Render.withData(() => {
  console.log('WHY AM I NOT HERE?')
  return store.things(2)
}, class extends Component {
  static displayName = 'Child'

  constructor() {
    super()
    console.log(2)
  }

  render() {
    return <div>Wtf {store.getState().caca}</div>
  }
})

Render.toString(App, {}).then((markup) => {
  console.log('@', markup)
}).catch((err) => {
  console.log('uhoh', err)
})


Contributor guide