Code Monkey home page Code Monkey logo

project-minimek's Introduction

Project Mini-Mek

A sample application to accompany the Practical Redux blog series by Mark Erikson, demonstrating various useful Redux techniques.

This is a miniature version of the MekHQ Battletech campaign force manager tool. The tentative list of planned features includes:

  • Load JSON data describing the pilots and Battlemechs in a combat force
  • For both pilots and Battlemechs:
    • Show a list of all items
    • Allow selection of an item in the list, and show details of the selected item
  • Edit the details for a pilot
  • Organize the pilots and their mechs into "lances" of four mechs, and the "lances" into a "company" of three lances.
  • Add and remove pilots and mechs from the force
  • Save the force back out to JSON

Please feel free to discuss implementation questions in both issues and pull requests! I'm happy to talk about why I did things a certain way.

project-minimek's People

Contributors

markerikson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project-minimek's Issues

Debouncing inputs means that there's a time period where the Redux state is incorrect

To reproduce:

  1. Increase the default debounce time:

    diff --git a/src/common/components/FormEditWrapper.jsx b/src/common/components/FormEditWrapper.jsx
    index 2276e58..800c4a0 100644
    --- a/src/common/components/FormEditWrapper.jsx
    +++ b/src/common/components/FormEditWrapper.jsx
    @@ -24,7 +24,7 @@ class FormEditWrapper extends Component {
             onChangePropName : "onChange",
             singleValue : false,
             passIsEditing : true,
    -        dispatchDelay : 250,
    +        dispatchDelay : 2500,
         }
    
         constructor(props) {

    This isn't required, but it makes it much easier to demonstrate.

  2. Create a new pilot, set the name, and save the changes:

    debounce

    (please ignore the failure at the end, it seems to be an unrelated issue)

  3. Note that the state saved to the store does not have the entered pilot name:

    Pilot: {
      items: [
        'cjrb9jhul00003f5viun8eqwk'
      ],
      itemsById: {
        cjrb9jhul00003f5viun8eqwk: {
          name: 'New Pilot',  // <------- HERE
          rank: 'Private',
          gunnery: 4,
          piloting: 5,
          age: 25,
          id: 'cjrb9jhul00003f5viun8eqwk'
        }
      },
      meta: {
        maxId: null
      }
    }
    Relevant Actions
    {
      type: 'PILOT_EDIT_START'
    }
    {
      type: 'PILOT_EDIT_STOP'
    }
    {
      type: 'EDIT_ITEM_APPLY',
      payload: {
        itemType: 'Pilot',
        itemID: 'cjrb9jhul00003f5viun8eqwk'
      }
    }
    {
      type: 'EDIT_ITEM_STOP',
      payload: {
        itemType: 'Pilot',
        itemID: 'cjrb9jhul00003f5viun8eqwk'
      }
    }
    {
      type: 'PILOT_SELECT',
      payload: {
        currentPilot: null
      }
    }

If you wait for the debounce timeout length after editing, then you will get an additional action and the application works:

{
  type: 'EDIT_ITEM_UPDATE',
  payload: {
    itemType: 'Pilot',
    itemID: 'cjrb9rai700003f5vqeja41be',
    newItemAttributes: {
      name: 'hello'
    }
  }
}

Relatedly, it's my understanding that in general you should make use of the debounced function's .clear() or .flush() methods when the component is unmounted, otherwise you might call the function after the component is gone. This isn't a problem with this example, but in a larger one that makes use of this it could be and React will warn about it.

If you do use flush(), you might get a state update "too late", which can cause strange issues. In our case, the UI was updated and thus it "looked right", but the data was never sent to the backend.


In our case, we triggered this type of behavior by using automated tests. These tend to be much faster at entering data and submitting forms.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.