Chen Jian's Java Blog 

Redux - avoid to pass props down component tree manually - 4. Build container components more easily with connect()

by Chen Jian


Posted on 2018-06-19 12:00 in Frontend


With connect() you don't have to manually write the container component as a Component class. const CounterComponentContainer = connect( // store.state => props of child component. Normally it's extracted as a function called...


Redux - avoid to pass props down component tree manually - 3. Use an extra container component to keep the original one reusable

by Chen Jian


Posted on 2018-06-19 12:00 in Frontend


So a "container" component will be introduced to wrap the original one. The container component will adapt the store structure to "input parameters" the original one needs. Therefore, the original one doesn't need to access store directly...


Redux - avoid to pass props down component tree manually - 2. Use Provider to make store accessible to all components

by Chen Jian


Posted on 2018-06-19 12:00 in Frontend


This way every component in the tree can access the store directly. So you don't need to pass the store manually any more This solution is actually based on React's Contenxt . function render(){ ReactDOM.render( <Provider...


Redux - avoid to pass props down component tree manually - 1. Pass the store down

by Chen Jian


Posted on 2018-06-19 12:00 in Frontend


In the basic example you can see props are passed down the compoent tree manually at every level. It's very anoying. A simple way to avoid this is to pass Redux store down at every level. It will simplify the code to some extent function...


Redux weird thing 2 - You can still have local state in components

by Chen Jian


Posted on 2018-06-19 12:00 in Frontend


Disclamer: "Weird" is a neutral word here. In Redux you are supposed to put "all" the data in the store. However, "temp" data like unsubmitted form input, should be inside the components. Data in the store should be cleaned, "official" daa.


Redux weird thing 1 - combineReducers

by Chen Jian


Posted on 2018-06-18 12:00 in Frontend


If your root component has more than one child component, you will have a big state , so is your reducer // the initial state const initialState = { counter: { value: 0 }, toDo: { itemList: [ {id: 1, text:...


A linux function to make current java code directory into a tarball without including unwanted files

by Chen Jian


Posted on 2018-06-17 12:00 in Linux/Unix/Windows


Put the following function into your ~/.bashrc, and run "tarcode" in your code directory. It will generate a *.tgz file under ~/temp tarcode() { filename=`basename "$PWD"` filename+='-' filename+=`date...


Dynamic file name in log4j's file appender

by Chen Jian


Posted on 2018-06-17 12:00 in Java


In your log4j.xml, set the file name as a variable <appender name="my-file-appender" class="org.apache.log4j.FileAppender"> <param name="file" value="${myFilePath}" /> <!-- ... --> </appender> Then in your java...


Quick log4j set up

by Chen Jian


Posted on 2018-06-17 12:00 in Java


<!-- pom.xml --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.slf...


Basic Redux Counter example

by Chen Jian


Posted on 2018-06-15 12:00 in Frontend


In this example, The "CounterComponet" is included by the root component called "AppComponent". No Store composition is used here. You still have to pass the props to "AppComponent", which in turn passes...


Frontend frameworks and things you should know in addition to React/Angular

by Chen Jian


Posted on 2018-06-11 12:00 in Frontend


Language ES2015 : A new generation of Javascript language specs. It supports modules and classes. It's also know as ES6 Typescript : An object-oriented language that will be converted to Javascript and then be run in browsers ...


How to prevent Quartz from re-firing a job while it is still running

by Chen Jian


Posted on 2018-06-04 12:00 in Java


Answer: use @DisallowConcurrentExecution Example Without this annotation import java.time.LocalTime; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobExecutionContext; import...


Quartz concepts

by Chen Jian


Posted on 2018-06-04 12:00 in Java


Basic concepts Job: What to do Trigger: When to do it Scheduler: The director to associate triggers to jobs and to invoke the trigger A job can be associated with several triggers, but a...


Forwarded servlet request won't be intercepted by filters

by Chen Jian


Posted on 2017-12-13 12:00 in Java


The new request created by RequestDispatcher.forward(request, response) will not be intercepted by its matching filters defined in web.xml To make a filter work for requests created by dispatcher, you have to add 2 dispatcher configurations to your...


The most reliable way of setting up username/password for Ethernet connection on Centos

by Chen Jian


Posted on 2017-10-30 12:00 in Linux/Unix/Windows


sudo yum install nmtui sudo nmtui Then "Activate Connection". Then the system will prompt you to input username/password