Upgrading from Marty 0.8 to 0.9


Marty now requires every store, action creator, query and state source to have a unique Id (e.g. "UserStore"). If you've been populating displayName then the easiest thing to do is rename displayName to id and your application will behave the same.

replaceState & setState

Store#setState has been renamed to Store#replaceState. Store#setState will now merge the existing state with the new state. This is to more closely follow the React API.

HttpStateSource no longer throws an error if Status Code >= 400

If the status code of an HTTP response is >= 400, we will no longer throw an error. If you wish to retain this behavior then you can add an HTTP hook

    id: 'throw-error',
    after(res) {
        if (!res.ok) {
          throw res;

Defining action types

In Marty v0.8 and below we had a different way of defining an action creators type which has now been deprecated:

var UserActionCreators = Marty.createActionCreators({
  updateEmail: UserConstants.UPDATE_EMAIL(function (userId, email) {
    this.dispatch(userId, email);
  deleteEmail: UserConstants.DELETE_EMAIL()

Why was it deprecated?

There were 3 reasons: 1. Automatic error handling made debugging really difficult (#127). 2. Automatically dispatched actions were confusing and not that helpful (#157, #152). 3. It didn't play nicely with ES6 classes

We decided this code wasn't adding any value so we should move towards a simpler more explicit approach.

In v0.9 you will see warnings in your code to move to the new style and we will remove the code entirely in v0.10.

How do I migrate my code to the new style?

All you need to do is move the constant to being the first argument of the dispatch function. If you utilizing auto dispatch constants then you will need to use marty/autoDispatch.

var autoDispatch = require('marty/autoDispatch');

var UserActionCreators = Marty.createActionCreators({
  updateEmail: function (userId, email) {
    this.dispatch(UserConstants.UPDATE_EMAIL, userId, email);
  deleteEmail: autoDispatch(UserConstants.DELETE_EMAIL)