Redux + Typescript: The type of the root state

You can get the type of the state from the root reducer // the reducer const appReducer = combineReducers({ global: globalStateReducer, example: exampleReducer }); type AppState = ReturnType<typeof appReducer> However the redux state can be cleared in some scenarios, so it should be undefinable //See https://stackoverflow.com/a/35641992/301447 for “undefined redux state” type RootState = AppState | …

Redux + Typescript: The type of the root state Read More »

Redux + Typescript: Use class to define Actions

You want the actions to be typed. You should use interface or class. Class is better than interface because in interfaces you cannot define the action "type" as a constant, but in classes you can: class LoadingStartedAction implements Action{ readonly type = LOADING_STARTED } However a class instance is not a plain object, but Redux …

Redux + Typescript: Use class to define Actions Read More »

Read process output in Java without hanging the main thread

/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * “License”); you may not use this …

Read process output in Java without hanging the main thread Read More »

Gradle upload a custom-generated jar file to Nexus

Do this: apply plugin: ‘maven-publish’ publishing { publications { maven( MavenPublication ) { artifact theTaskThatGeneratesJar } } repositories { maven { def releasesRepoUrl = http://…/repositories/releases/’ def snapshotsRepoUrl = ‘http://…/repositories/snapshots/’ url = version.endsWith(‘SNAPSHOT’) ? snapshotsRepoUrl : releasesRepoUrl credentials { username ‘xxx’ password ‘xxx’ } } } }

React Component: A pair of componentDidMount() and componentWillUnmount() may cause infinite loop if error is thrown from render

The following will cause an infinite loop. The render() method will be called again and again. class ToDoItemEditComponentContainer extends React.Component { componentDidMount() { this.props.loadItem(); //load item remotely and put it in the local redux store } componentWillUnmount() { this.props.clearItemLocally(); //remove item from local redux store } render() { throw “some error” } } Here is …

React Component: A pair of componentDidMount() and componentWillUnmount() may cause infinite loop if error is thrown from render Read More »

My practice of fetching data for List/Detail components in React/Redux

The user experience it should have When you go to a detail page from the list page or with a direct URL, the detail page should show the up-to-date data When you go to the list page with a direct URL, the list page should show the up-to-date data When you RETURN to the list …

My practice of fetching data for List/Detail components in React/Redux Read More »