goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

0.18.x breaks generateActions/createActions that worked in 0.17.x? #666

Closed westhomas closed 8 years ago

westhomas commented 8 years ago

The following code works great for 0.17.9. But it seems 0.18 an upwards breaks. The calls to this.actions.* will break due to actions being undefined.

I'm assuming this could be related to the breaking changes in 0.18.0 but I'm not entirely sure why that would apply here.

import alt from '../alt'
import { ajax } from 'jquery'

class MuhActions {
  constructor() {
    this.generateActions(
      'getCartsSuccess',
      'getCartsFail'
    )
  }

  getCarts() {
    ajax({ url: '/api/carts' })
      .done((data) => {
        this.actions.getCartsSuccess([{'id': 1, 'created': (new Date()).toString(), 'userId': 123, 'firstName': 'Bob', 'lastName': 'Boberson'}])
      })
      .fail((jqXhr) => {
        this.actions.getCartsFail("testing123")
      })
  }

}

export default alt.createActions(MuhActions)
goatslacker commented 8 years ago

now you can just call this.getCartsSuccess directly.

p10ns11y commented 7 years ago

@goatslacker : How to call/refer another actions in the ActionClass ?

import alt from '../alt'
import { ajax } from 'jquery'

class MuhActions {
  constructor() {
    this.generateActions(
      'getCartsSuccess',
      'getCartsFail'
    )
  }

  updateSomething() {
     ajax()...
  }

  getCarts() {
    ajax({ url: '/api/carts' })
      .done((data) => {
        this.getCartsSuccess([{'id': 1, 'created': (new Date()).toString(), 'userId': 123, 'firstName': 'Bob', 'lastName': 'Boberson'}])
       this.updateSomething()
      })
      .fail((jqXhr) => {
        this.getCartsFail("testing123")
      })
  }

}

export default alt.createActions(MuhActions)

this.updateSomething() => someStore.onUpdateSomething() or thisAction.updateSomething