🏋️♀️
This file contains 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
let currentHook: Hook | null = null; | |
let workInProgressHook: Hook | null = null; | |
function mountWorkInProgressHook(): Hook { | |
const hook: Hook = { | |
memoizedState: null, | |
baseState: null, | |
baseQueue: null, |
This file contains 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
function mountStateImpl<S>(initialState: (() => S) | S): Hook { | |
const hook = mountWorkInProgressHook(); | |
if (typeof initialState === 'function') { | |
const initialStateInitializer = initialState; | |
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types | |
initialState = initialStateInitializer(); | |
if (shouldDoubleInvokeUserFnsInHooksDEV) { | |
setIsStrictModeForDevtools(true); | |
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types | |
initialStateInitializer(); |
This file contains 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
function mountState<S>( | |
initialState: (() => S) | S, | |
): [S, Dispatch<BasicStateAction<S>>] { | |
const hook = mountStateImpl(initialState); | |
const queue = hook.queue; | |
const dispatch: Dispatch<BasicStateAction<S>> = (dispatchSetState.bind( | |
null, | |
currentlyRenderingFiber, | |
queue, | |
): any); |
This file contains 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
function dispatchSetState<S, A>( | |
fiber: Fiber, | |
queue: UpdateQueue<S, A>, | |
action: A, | |
): void { | |
const lane = requestUpdateLane(fiber); | |
const update: Update<S, A> = { | |
lane, | |
revertLane: NoLane, |
This file contains 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 function useState<S>( | |
initialState: (() => S) | S, | |
): [S, Dispatch<BasicStateAction<S>>] { | |
const dispatcher = resolveDispatcher(); | |
return dispatcher.useState(initialState); | |
} |
This file contains 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 React = (function () { | |
let _state; | |
return { | |
useState: function (initialValue) { | |
if (typeof _state === 'undefined') _state = initialValue; | |
function setState(newVal) { | |
_state = newVal; | |
} | |
return [_state, setState]; | |
}, |
This file contains 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
function useState(initialValue) { | |
var _state = initialValue // private value | |
function state() { | |
return _state | |
} | |
function setState(newVal) { | |
_state = newVal | |
} | |
return [_state, setState] // exposing functions for external use | |
}; |
This file contains 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
let count = 0; | |
function add() { | |
count++; | |
} | |
add(); | |
console.log(count); // 1 |
This file contains 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 { sleep } = require('@brickwise/express-utility'); | |
const app = require('express').Router(); | |
const UserService = { | |
getUser: (username) => { | |
} | |
} | |
// V1 | |
app.post('/login', async (req, res) => { |
This file contains 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
// Step -2 - Bugs | |
// Step -1 - Dirty Way | |
// Step 0 - Projection should only accepts fields from interface | |
// Step 1 - Projection should be typed and only accepts mongodb valid values[0, 1, true, false] | |
// Step 2 - Projection should be optional | |
// Step 3 - Projection should support nested projection | |
// Step 4 - Projection should support nested projection with arrays(i) | |
// Step 5 - Projection should be nested optional | |
// Step 6 - MongoDB Projection rule, inclusion and exclusion cannot be mixed | |
// - Function output should match the projection: |
NewerOlder