1:1 - Constants : const
Action creators : functions
export function updateEmail (userId, email) {
return {
type: 'UPDATE_EMAIL',
payload: { userId, email }
}
}
import { Component } from "React"; | |
export var Enhance = ComposedComponent => class extends Component { | |
constructor() { | |
this.state = { data: null }; | |
} | |
componentDidMount() { | |
this.setState({ data: 'Hello' }); | |
} | |
render() { |
// functional publish/subscribe | |
let Observers = []; | |
function subscribe(observer) { | |
Observers.push(observer); | |
} | |
function publish(event) { | |
Observers.forEach((observer) => { | |
observer(event); |
{ | |
"name": "lander", | |
"version": "0.0.3", | |
"description": "", | |
"main": "app.js", | |
"author": "Sze-Hung Tsui <danielt213@gmail.com>", | |
"scripts": { | |
"start": "node .", | |
"lint": "eslint * --cache --quiet --fix", | |
"lint-css": "stylelint '**/*.css'" |
const webpack = require('webpack'); | |
const path = require('path'); | |
const FlowStatusWebpackPlugin = require('flow-status-webpack-plugin'); | |
// const styleLintPlugin = require('stylelint-webpack-plugin'); | |
// const globPath = path.join(__dirname, 'app') + '/**/*.css'; | |
// const globPath = path.join(__dirname, 'app', 'js', 'components', '404Page') + '/404Page.css'; | |
// console.log("PATH ::", globPath); | |
module.exports = { |
// @flow | |
import React from 'react'; | |
import styles from './SiteRow.css'; | |
import classnames from 'classnames'; | |
import _ from 'lodash/fp'; | |
import R from 'ramda'; | |
/** | |
* Vanilla JS | |
*/ |
var express = require('express') | |
express().use('/',express.static(__dirname)).listen(8080); | |
console.log("Listening on 8080..."); |
1:1 - Constants : const
Action creators : functions
export function updateEmail (userId, email) {
return {
type: 'UPDATE_EMAIL',
payload: { userId, email }
}
}
#Translating Marty to Redux
Some people have asked how I've translated a Marty app to Redux. Once you get your head around how Redux works I found concepts in Marty translated easily. Below is side-by-side comparison of the two libraries to help you along the way.
Also if you're looking for some devtools, check out redux-devtools.
##Constants
Marty
I hereby claim:
To claim this, I am signing this object:
//spike code | |
import smoothScroll from 'smooth-scroll/dist/js/smooth-scroll'; | |
function goTo(href, offset) { | |
console.log("goTo:", href, offset); | |
smoothScroll.animateScroll(href, null, { updateURL: false, offset: offset || 0 }) | |
} | |
window.goTo = goTo; | |
console.log('goTo assigned: ', goTo); |