What will the window.origin be in html5 sandbox iframes?

I did a test about this. If Your site is www.host.com The iframe src is also www.host.com Then sanbox + "allow-same-orign" enabled => window.origin will be "www.host.com" sanbox + "allow-same-orign" DISABLED => window.origin will be null If Your site is www.host.com The iframe src is www.guest.com Then sanbox + "allow-same-orign" => window.origin will be "www.guest.com" …

What will the window.origin be in html5 sandbox iframes? Read More »

Redux weird thing 3 – Action Creator

You can dispatch an action inside your component, for example, when a button is clicked, like render(){ return ( <div> … <div> <button onClick={ e => this.context.store.dispatch({type: ‘counterChange’, amount: 1}) }> + </button> <button onClick={ e => this.context.store.dispatch({type: ‘counterChange’, amount: -1}) }> – </button> </div> </div> ); } But a more preferred way is to …

Redux weird thing 3 – Action Creator Read More »

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

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 mapStateToProps() state => { return {counter: state.counter} }, // store.dispatch => props of child component. Normally it’s extracted as a function called …

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

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

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 and will be reusable again. //The reusable component, which doesn’t access store any more class CounterComponent extends Component …

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

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

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 store = {rootStore}> <AppComponent appName=”React Demo Site”/> </Provider>, document.getElementById(‘root’)); } class AppComponent extends Component { render() { return ( <div …

Redux – avoid to pass props down component tree manually – 2. Use Provider to make store accessible to all components Read More »

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

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 render(){ ReactDOM.render( <AppComponent appName=”React Demo Site” store={rootStore}/>, document.getElementById(‘root’)); } class …

Redux – avoid to pass props down component tree manually – 1. Pass the store down Read More »

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

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 ‘+%Y-%m-%dT%H%M%S’` filename=$HOME’/temp/’$filename’.tgz’ echo $filename tar –exclude=’.git’ –exclude=’.DS_Store’ –exclude=’.classpath’ –exclude=’.gitignore’ –exclude=’.project’ –exclude=’.settings’ –exclude=’target’ -zcvf $filename . }