This script is based on this StackOverflow answer, with some modifications to fix its issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { rest } from "msw"; | |
// https://vitejs.dev/guide/features.html#glob-import | |
const imports = import.meta.glob("./api/**/*.ts", { eager: true }); | |
export const handlers = Object.entries(imports).reduce( | |
(allHandlers, [path, handlers]) => { | |
// map "./path/[to]/handlers.js" -> "/api/path/:to/handlers" | |
const apiPath = | |
"/" + |
To delete all local branches that are already merged into the currently checked out branch:
git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs git branch -d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expected output: | |
// | |
// const oa = createBuilder('/oa') | |
// oa() /oa | |
// oa.meetingroom() /oa/meetingroom | |
// oa.meetingroom.add() /oa/meetingroom/add | |
// | |
// Yep it's a endpoint builder and can evolve to be a api caller | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeScript 26 mins βββββββββββββββββββββ 96.8% | |
CSS 0 secs βββββββββββββββββββββ 2.6% | |
JSON 0 secs βββββββββββββββββββββ 0.6% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function useAbortableAsyncCallback(callback, inputs) { | |
const abortHandleRef = useRef(); | |
const runAbortHandle = useCallback(() => { | |
if (abortHandleRef.current) { | |
abortHandleRef.current(); | |
} | |
}, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hook for use props as a tween state | |
// Usage. | |
// function Component({ propA, ...props }) { | |
// const tweenA = useAsTween(propA); | |
// // ... | |
// } | |
// | |
import { useEffect } from 'react'; | |
import useTweenState from './useTweenState'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-tabs,no-mixed-operators */ | |
import * as d3 from 'd3'; | |
/** | |
* @see http://bl.ocks.org/nbremer/21746a9668ffdf6d8242#radarChart.js | |
*/ | |
function createRadarChart(selector, data, options) { | |
const defaultOptions = { | |
w: 600, // Width of the circle | |
h: 600, // Height of the circle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux'; | |
export default connect( | |
state => ({ state }), // mapState2Props | |
)( | |
({ state, dispatch, children }) => children(state, dispatch), // <Store> component | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const endpoints = registerEndpoints( | |
GET`/users`([User]), | |
GET`/users/:id`(User), | |
POST`/users`(User), | |
) | |
const users = await endpoints.getUsers.call() | |
const user1 = await endpoints.getUsersId.call({id: 1}) |
NewerOlder