Skip to content

Instantly share code, notes, and snippets.

@oampo
Last active September 28, 2016 00:18
Show Gist options
  • Save oampo/c61ec31b0378fc398641017160484e19 to your computer and use it in GitHub Desktop.
Save oampo/c61ec31b0378fc398641017160484e19 to your computer and use it in GitHub Desktop.

Loading and saving the Trello state

Loading the state

  • Import and apply the Redux Thunk middleware

  • Add some initial content to the db.json file:

    {
        "lists": [{
            "id": 0,
            "title": "First list"
        }, {
            "id": 1,
            "title": "Second list"
        }],
        "cards": [{
            "id": 0,
            "text": "Example card",
            "listId": 0
        }, {
            "id": 1,
            "text": "Another card",
            "listId": 0
        }, {
            "id": 2,
            "text": "Example card in list 2",
            "listId": 1
        }, {
            "id": 3,
            "text": "Another card in list 2",
            "listId": 1
        }]
    }
  • Reset the initialState of your app to:

    {
        lists: []
    }
  • Add an async action and its sync counterparts for fetching the lists:

  • Update the reducer to handle the sync actions.

  • Dispatch the fetchLists() action from the Board's componentDidMount method.

  • Test out your app - you should see the contents of your database being loaded.

Saving the state

  • Rename your current addCard and addList actions to addCardSuccess and addListSuccess.
  • Add async actions and their remaining sync counterparts for adding a new card and a new list to the database:
  • Update the reducer to handle the sync Request and Error actions - it should already handle the Success actions.
  • Test out your app - adding cards and lists should see them added to db.json, and the additions should be reflected in the app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment