Kamran Ayub
👨👩👦 🐶
🎲🎮👨💻📚🎸
Work at Target
To make my apps easier to maintain
To make my apps easier to scale
Easy to extend
Easy to collaborate on
Easy to reuse code
Easy to refactor
Easy to understand
Easy to test
Folder Layout
State & Reducers
Actions
Props & State
Action Creators
Folder Layout
Folder Layout
Not scalable as screens nest further
Folder Layout
Emulate Node resolution, search each directory upwards
Maintains F12 Go to Definition behavior
Folder Layout
There's an open issue for this
Folder Layout
const path = require("path");
const fs = require("fs");
const klaw = require("klaw-sync");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const tsconfig = require("./tsconfig.json");
// Find shared folders
const searchPath = path.join(__dirname, "new/src/");
const paths = klaw(searchPath, {
nofile: true
})
.filter(({ path: p }) => path.basename(p) === "shared")
.map(({ path: p }) => path.join(path.relative(searchPath, p), "*"));
// Override tsconfig paths
tsconfig.compilerOptions.paths = {
...tsconfig.compilerOptions.paths,
"shared/*": paths
};
// Write temp tsconfig
fs.writeFileSync(
path.join(__dirname, "tsconfig.temp.json"),
JSON.stringify(tsconfig)
);
module.exports = {
resolve: {
extensions: [".ts", ".tsx", ".js"],
// Use temp config for resolving paths
plugins: [new TsconfigPathsPlugin({ configFile: "tsconfig.temp.json" })]
},
mode: "development",
entry: "./index.tsx",
context: path.resolve(__dirname, "new/src"),
output: {
filename: "build/bundle.js"
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: "ts-loader" }
]
}
};
Folder Layout
Folder Layout
State & Reducers
No need to define an entire representative "State" interface. Just export what it will end up being (typeof)
Folder Layout
Each screen will define its state shape
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
A bit wordy, but pays off at scale
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Action Creators
Folder Layout
Actions
State & Reducers
Properly types dispatch function
Action Creators
Folder Layout
Actions
State & Reducers
Action Creators
Folder Layout
Actions
State & Reducers
Action Creators
Folder Layout
Actions
State & Reducers
Props & State
Folder Layout
Actions
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Can pull into type alias and share
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Need a way to get "dispatch" and separate Redux state props vs. "own" props
Extract stateless type alias to encapsulate our State and reduce DispatchProp usage
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Same as stateless, create encapsulated Redux component type
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers