Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

kmsheng kmsheng

🏠
Working from home
View GitHub Profile
@kmsheng
kmsheng / shallowEqual.ts
Last active Apr 8, 2019
redux-react-hook / src / shallowEqual.ts
View shallowEqual.ts
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
// From https://github.com/reduxjs/react-redux/blob/3e53ff96ed10f71c21346f08823e503df724db35/src/utils/shallowEqual.js
const hasOwn = Object.prototype.hasOwnProperty;
// 這個是 Object.is 的 polyfill 版本,應該是給 IE 看的...
function is(x: any, y: any) {
if (x === y) {
return x !== 0 || y !== 0 || 1 / x === 1 / y; // 這裡使 +0 與 -0 比對會是 false
@kmsheng
kmsheng / create.ts
Last active Apr 8, 2019
redux-react-hook / src / create.ts
View create.ts
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import {
createContext,
useContext,
useEffect,
useMemo,
useReducer,
useRef,
} from 'react';
@kmsheng
kmsheng / index.ts
Last active Apr 8, 2019
redux-react-hook / src / index.ts
View index.ts
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import {create} from './create'; // 將 create 方法從檔案 create.ts 引入
// 底下呼叫 create 方法的 return 結果 StoreContext, useDispatch 和 useMappedState export 出去
// 這樣外部檔案可以使用 import 語法叫用
export const {StoreContext, useDispatch, useMappedState} = create<
any,
any,
any
View check.js
const add = require('./add');
console.log(`1 + 1 = ${add(1, 1)}`);
@kmsheng
kmsheng / Makefile
Created Aug 15, 2018
include example
View Makefile
include ./Makefile2.mk
all: target
@kmsheng
kmsheng / Makefile
Last active Aug 15, 2018
.INTERMEDIATE example
View Makefile
all: pre target1
pre:
@echo "running pre"
@touch pre
target1:
@echo "target1"
.PHONY: all pre target1
@kmsheng
kmsheng / Makefile
Created Aug 15, 2018
without .PHONY
View Makefile
all: target1
target1:
@rm -f target1
@touch target1
View Makefile
all: target1
target1:
@rm -f target1
@touch target1
.PHONY: all target1
View gist:c89a3852983921bc5d790c410a6f4341
all: target1 target2
target1:
@echo "Running $@"
target2:
@echo "Running $@"
@kmsheng
kmsheng / Makefile
Created Aug 15, 2018
Notice $@ and $* are quite different compare to shell script
View Makefile
all:
@echo "No target goes here"
target%:
@echo "\"\$$@\" = $@"
@echo "\"\$$*\" = $*"
@echo "\$$@ =" $@
@echo "\$$* =" $*