Updating Packages: Payload? Portfinder?

I took a couple of weeks off while guests came and went.  When I got back to my keyboard I checked to see what npm packages were outdated by using the command “npm outdated”.  Since my software is not yet in production, I’m fairly cavalier about updating packages to their latest version.

Thus I saw that Ngrx had been updated to 4.0 from its previous 2.x version.  After dutifully changing the version numbers in my package.json file and re-running npm install, I unsuccessfully tried to compile and run my program.

First I dealt with all the Ngrx issues by following the migration guide  and was really surprised to see that the payload property had been removed from the Action interface.  After fuming for a few seconds, I realized how nice this is.  Consider for a second this bit of code from a reducer:

     const userData = action.payload; ...

Previously, this code would compile under certain circumstances (like above, when the type wasn’t provided for userData).  But what if you hadn’t defined a payload for the action because it was not required?  What if your payload was inadvertently a different type than you actually wanted?

By removing the payload property from the Action interface, you are forced to cast the type of action to the one you really need.  This prevents incorrect assumptions and clarifies the code.  By stating the type of the expected payload and casting your action to the expected action that has that type of payload your intentions become clear and the possibility of misinterpretation or run-time errors is reduced:

    const thisAction = action as LoadUserSuccessAction;
    const userData: UserData = thisAction.payload; ...

The only thing I was really sad about is that, due to performance issues, the Ngrx dev tools integration is temporarily not available. I enjoyed being able to look at the Redux tab in the Chrome dev tools to see what my state was and how it had arrived to confirm that my code was working as expected.  However, they do say they are working to fix the issues and I hope to see it available again soon.

Ngrx issues fixed, I once again attempted to compile and run.  Now I kept getting an error saying that the portfinder module could not be found.  This problem has been reported sporadically over the past year, and advice differed, but I took the scorched earth approach and deleted my node-modules directory entirely and then installed everything clean.  I believe the issue was that not all levels of the node packages were updated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s