Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
220fe41
FY-64/chore: add currentDispatcher
JinmuGo Jan 23, 2024
cd9bfa1
FY-64/chore(hook): add hookCore properties
JinmuGo Jan 24, 2024
6e98c80
FY-64/refactor: folder structure
JinmuGo Jan 25, 2024
bf8c2d4
FY-64/chore: modify constants
JinmuGo Jan 25, 2024
1ba17c9
FY-64/chore(workInProgressHook): add workInProgressHook function
JinmuGo Jan 25, 2024
c81e2c8
FY-64/chore(dispatcher): add hookDispatcher
JinmuGo Jan 25, 2024
5178aa5
FY-64/chore: init hooks prototype
JinmuGo Jan 25, 2024
c1014af
fix(effectTag): reDefinition HookEffectTags
JinmuGo Feb 8, 2024
2eba7a7
FY-67/feature use reducer (#12)
JinmuGo Feb 16, 2024
870b3af
FY-64/fix: renderWithHooks
JinmuGo Feb 16, 2024
05282f4
FY-64/fix: workInProgressHook의 로직 에러 throw
JinmuGo Feb 16, 2024
033cf87
FY-137/feature use effect (#13)
JinmuGo Feb 19, 2024
67f03e6
FY-64/docs(hooks): add comment for pushEffect
JinmuGo Feb 19, 2024
457770e
FY-64/docs: enqueueRenderPhaseUpdate add comment
JinmuGo Feb 20, 2024
b011752
FY-187/feat(hook): add useRef (#19)
JinmuGo Feb 22, 2024
9b43ac8
feat(hooks): add useCallback (#18)
JinmuGo Feb 22, 2024
babe474
feat(hook): add useState (#16)
JinmuGo Feb 22, 2024
7f3c908
FY-179/feat(hooks): add useLayoutEffect (#15)
JinmuGo Feb 22, 2024
e1eb6a5
FY-185/feat(hooks): add useMemo (#17)
JinmuGo Feb 22, 2024
4686b42
FY-64/style: apply eslint formatting
JinmuGo Feb 23, 2024
2fa6641
FY-190/hook refactoring (#20)
JinmuGo Feb 23, 2024
d51f664
FY-193/feat(hookObject): renew to 16.12.0
JinmuGo Feb 25, 2024
125d3c4
FY-193/style: small fix in prettier,eslint
JinmuGo Feb 25, 2024
d7600ba
FY-193/feat(hookCore): renew to 16.12.0
JinmuGo Feb 25, 2024
fa43a91
FY-193/style: apply new style rule
JinmuGo Feb 25, 2024
0f1525d
FY-193/feat(hookUpdateQueue): renew 16.12.0
JinmuGo Feb 25, 2024
9bb36d0
FY-193/feat(workInProess): renew to 16.12.0
JinmuGo Feb 25, 2024
707b368
FY-193/feat(hookUpdate): renew 16.12.0
JinmuGo Feb 25, 2024
8e27d87
FY-193/feat(hookExpirationTime): add new Object for expirationTime
JinmuGo Feb 25, 2024
7cab6db
FY-193/feat(hookRenderPhaseCore): add new Object for render phase update
JinmuGo Feb 25, 2024
912b770
FY-193/fix: export statement
JinmuGo Feb 26, 2024
87d95a7
FY-193/chore(hook): small fix core
JinmuGo Feb 26, 2024
516756b
FY-193/feat(dispatcher): add ContextOnlyDispatcher
JinmuGo Feb 26, 2024
71ef595
FY-193/fix: a typo add .js suffix
JinmuGo Feb 26, 2024
f22023e
FY-193/chore: add NoWork in fiberExpirationTime
JinmuGo Feb 26, 2024
b183d8b
FY-193/feat(hook): back to the 16.12.0 renderWithHooks
JinmuGo Feb 26, 2024
be8dc59
FY-193/feat(hook): enqueueRenderPhaseUpdate
JinmuGo Feb 26, 2024
5964a0d
FY-193/feat(hook): back to the 16.12.0 useReducer & dispatchAction
JinmuGo Feb 26, 2024
ab7a02d
FY-193/feat(hook): renew useState
JinmuGo Feb 26, 2024
79a6dff
FY-193/feat(hook): add useEffect
JinmuGo Feb 27, 2024
3587e38
FY-193/feat(hook): renew useLayoutEffect
JinmuGo Feb 27, 2024
761f7db
FY-193/remove: dummy
JinmuGo Feb 29, 2024
990d341
FY-193/ci(scripts): add execJsFile.sh
JinmuGo Feb 29, 2024
1ea6525
FY-193/fix(type): all type and execute confirm
JinmuGo Feb 29, 2024
33a5075
FY-193/docs: update comment
JinmuGo Feb 29, 2024
af72749
FY-193/ci(build_check): add script for confirm each file
JinmuGo Feb 29, 2024
81f05ea
FY-193/docs(hook): update comments
JinmuGo Mar 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintrc.cjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,12 +26,10 @@ module.exports = {
strict: ["error", "global"], // "use strict"
camelcase: "error", // camelCase 사용
"no-var": "error", // var is not allowed
indent: ["error", 4], // 4 spaces
"linebreak-style": ["error", "unix"], // LF
quotes: ["error", "double"], // use double quotes
semi: ["error", "always"], // always use semicolon
eqeqeq: ["error", "always"], // always use ===
"prettier/prettier": "error", // Prettier
"prefer-const": "error", // use const
"func-style": ["error", "expression"], // 함수 표현식 스타일 권장
"prefer-rest-params": "error", // Rest 파라미터 사용 권장
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/build_check.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,4 +29,8 @@ jobs:
if [ $? -ne 0 ]; then
echo "Build failed with error code $?"
exit 1
fi
fi
- name: Execute script forEach file
run: |
chmod +x ./scripts/run-tests.sh
./scripts/run-tests.sh
2 changes: 1 addition & 1 deletion .prettierrc
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
{
"semi": true,
"trailingComma": "es5",
"printWidth": 80,
"printWidth": 120,
"tabWidth": 4,
"useTabs": false
}
3 changes: 3 additions & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,5 +48,8 @@
"*.js": [
"eslint --cache ."
]
},
"dependencies": {
"lodash": "^4.17.21"
}
}
18 changes: 18 additions & 0 deletions scripts/execJsFile.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# 시작 디렉토리를 입력받거나 현재 디렉토리를 기본값으로 사용
START_DIR=${1:-../srcs/}
ERROR_OCCURRED=0

echo "Node.js로 실행할 JavaScript 파일 검색 중 ('type' 폴더 제외)..."
find "$START_DIR" -path "$START_DIR/type" -prune -o -name "*.js" -print | while read filename; do
echo "실행 중: $filename"
if ! node "$filename"; then
echo "오류 발생: $filename 실행 중 오류가 발생했습니다."
ERROR_OCCURRED=1
exit 1
fi
done

echo "모든 JavaScript 파일이 성공적으로 실행되었습니다."
exit 0
2 changes: 1 addition & 1 deletion srcs/core/createElement.js
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import isArray from "../shared/isArray";
import isArray from "../shared/isArray.js";

const RfsElement = (type, props, children) => {
return {
Expand Down
10 changes: 4 additions & 6 deletions srcs/core/createRoot.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,9 +17,9 @@
//todo: ReactDOMRoot.render
//todo: ReactDOMRoot.unmount

import { ELEMENT_NODE, DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE } from "./const";
import { ConcurrentRoot } from "../shared/type/TRootTag";
import { createFiberRoot } from "../fiber/fiberRoot";
import { ELEMENT_NODE, DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE } from "./const.js";
import { ConcurrentRoot } from "../type/TRootTag.js";
import { createFiberRoot } from "../fiber/fiberRoot.js";
//todo: dom.js
import { markContainerAsRoot } from "../dom/dom.js";
/**
Expand DownExpand Up@@ -87,9 +87,7 @@ const ReactDOMRoot = class {
*/
export const createRoot = (container) => {
if (!isValidContainer(container)) {
throw new Error(
"createRoot: container is not a valid DOM element -RFS error"
);
throw new Error("createRoot: container is not a valid DOM element -RFS error");
}
return new ReactDOMRoot(container);
};
Expand Down
14 changes: 14 additions & 0 deletions srcs/core/currentDispatcher.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
/**
* @file currentDispatcher.js
* @description This file defines the currentDispatcher object.
* @module core/currentDispatcher
*/

/**
* @property current {Object} The current dispatcher.
*/
const currentDispatcher = {
current: null,
};

export default currentDispatcher;
2 changes: 1 addition & 1 deletion srcs/dom/dom.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@
* 필요할 수 있다
*/

import { HostComponent, HostText, HostRoot } from "../shared/type/TWorkTag";
import { HostComponent, HostText, HostRoot } from "../type/TWorkTag.js";

/**
* @description 랜덤한 문자열 키를 생성합니다
Expand Down
9 changes: 0 additions & 9 deletions srcs/dummy/fibonacci.js

This file was deleted.

13 changes: 6 additions & 7 deletions srcs/fiber/fiber.js
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
import { HostRoot } from "../shared/type";
import { NoEffect } from "../shared/type/TSideEffectFlags";
import { Tfiber } from "../shared/type/TFiber";
import { NoWork } from "../shared/type/TExpirationTime";
import { ConcurrentMode } from "../shared/type/TTypeOfMode";
import { ConcurrentRoot } from "../shared/type/TRootTag";
import { HostRoot } from "../type/TWorkTag.js";
import { NoEffect } from "../type/TSideEffectFlags.js";
import { NoWork } from "../type/TExpirationTime.js";
import { ConcurrentMode } from "../type/TTypeOfMode.js";
import { ConcurrentRoot } from "../type/TRootTag.js";
/**
*
* @param {tag} TWorkTag
Expand DownExpand Up@@ -77,7 +76,7 @@ const createFiber = (tag, pendingProps, key, mode) => {

/**
*
* @param {tag} TRootTag -> shared/type/TRootTag.js
* @param {tag} TRootTag ->/type/TRootTag.js
* @returns fiber @type TFiber
* @description HostRoot에 대응되는 FiberNode를 생성하는 함수
*/
Expand Down
3 changes: 1 addition & 2 deletions srcs/fiber/fiberRoot.js
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
import { createHostRootFiber } from "./fiber.js";
import { TFiberRoot } from "../shared/type/TFiberRoot";
import { NoWork } from "../shared/type/TExpirationTime";
import { NoWork } from "../type/TExpirationTime.js";

/**
@description FiberRoot는 해당 Fiber에 대해서 관리를 위한 그 스코프내의 전역관리 공간이라고 생각할 수 있습니다.
Expand Down
21 changes: 21 additions & 0 deletions srcs/hooks/constructor/EffectInstance.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
/**
* @module EffectInstance
* @description - This class is used to create an destroy Object for effect instance.
* @see https://github.com/facebook/react/pull/26561
* @property {Function} destroy - The cleanup function of the effect.
*/
class EffectInstance {
constructor(destroy) {
this.destroy = destroy;
}
}

/**
* @description - This function creates an effect instance.
* @returns {Object} - An effect instance includes destroy function.
*/
const createEffectInstance = (destroy) => {
return new EffectInstance(destroy);
};

export default createEffectInstance;
23 changes: 23 additions & 0 deletions srcs/hooks/constructor/FunctionComponentUpdateQueue.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
/**
* @module FunctionComponentUpdateQueue
* @description - This class is used to create an update queue for function component.
* @property {TEffect} lastEffect - The last effect in the circular update queue.
*/
class FunctionComponentUpdateQueue {
constructor(lastEffect) {
this.lastEffect = lastEffect;
}
}

/**
* @description - This function creates an update queue for function component.
* stores와 events, memocache는 각각 다른 hook들에서 사용됩니다.
* 각각 [useSyncExternalStore, useEffectEvent, useMemoCache]에서 사용.
* 그래서 위의 property들은 제거되었습니다.
* @returns {Object} - An update queue for function component.
*/
const createFunctionComponentUpdateQueue = (lastEffect) => {
return new FunctionComponentUpdateQueue(lastEffect);
};

export default createFunctionComponentUpdateQueue;
26 changes: 26 additions & 0 deletions srcs/hooks/constructor/MemoizedStateAndDispatch.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
/**
* MemoizedStateAndDispatch
* @description - useReducer와 useState에서 사용되는 memoizedState와 dispatch를 생성하는 함수입니다.
*/
class MemoizedStateAndDispatch {
constructor(state, dispatch) {
this.state = state;
this.dispatch = dispatch;
}

toArray() {
return [this.state, this.dispatch];
}
}

/**
*
* @param {any} state
* @param {Function} dispatch
* @returns
*/
const createMemoizedStateAndDispatch = (state, dispatch) => {
return new MemoizedStateAndDispatch(state, dispatch).toArray();
};

export default createMemoizedStateAndDispatch;
26 changes: 26 additions & 0 deletions srcs/hooks/constructor/MemoizedValueAndDeps.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
/**
* MemoizedValueAndDeps
* @description - useMemo와 useCallback에서 사용되는 memoizedState를 생성하는 클래스입니다.
*/
class MemoizedValueAndDeps {
constructor(value, deps) {
this.value = value;
this.deps = deps;
}

toArray() {
return [this.value, this.deps];
}
}

/**
*
* @param {any} value
* @param {Array} deps
* @returns
*/
const createMemoizedValueAndDeps = (value, deps) => {
return new MemoizedValueAndDeps(value, deps).toArray();
};

export default createMemoizedValueAndDeps;
34 changes: 34 additions & 0 deletions srcs/hooks/constructor/effect.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
/**
*
* @param {import("../../fiber/type").TEffectTags} effectTag
* @param {Function} create
* @param {import("../types/THookEffectFlags").THookEffectFlags} inst
* @param {Array} deps
* @param {TEffect} next
* @see TEffectInstance
*/
const effect = class {
constructor(effectTag, create, inst, deps, next) {
this.effectTag = effectTag;
this.create = create;
this.inst = inst;
this.deps = deps;
this.next = next;
}
};

/**
*
* @param {import("../../fiber/type").TEffectTags} effectTag
* @param {Function} create
* @param {import("../types/THookEffectFlags").THookEffectFlags}
* @param {Array} deps
* @param {TEffect} next
* @returns {TEffect}
* @see TEffectInstance
*/
const createEffect = (effectTag, create, inst, deps, next) => {
return new effect(effectTag, create, inst, deps, next);
};

export default createEffect;
32 changes: 32 additions & 0 deletions srcs/hooks/constructor/hookObject.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
/**
*
* @param {any} memoizedState
* @param {any} baseState
* @param {any} baseUpdate
* @param {TUpdateQueue} queue
* @param {THookObject} next
*/
const hookObject = class {
constructor(memoizedState, baseState, baseUpdate, queue, next) {
this.memoizedState = memoizedState;
this.baseState = baseState;
this.baseUpdate = baseUpdate;
this.queue = queue;
this.next = next;
}
};

/**
*
* @param {any} memoizedState
* @param {any} baseState
* @param {any} baseUpdate
* @param {TUpdateQueue} queue
* @param {THookObject} next
* @returns
*/
const createHookObject = (memoizedState, baseState, baseUpdate, queue, next) => {
return new hookObject(memoizedState, baseState, baseUpdate, queue, next);
};

export default createHookObject;
31 changes: 31 additions & 0 deletions srcs/hooks/constructor/hookUpdate.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
*
* @param {any} action
* @param {boolean} hasEagerState
* @param {any} eagerState
* @param {THookUpdate} next
*/
const hookUpdate = class {
constructor(expirationTime, suspenseConfig, action, eagerReducer, eagerState, next) {
this.expirationTime = expirationTime;
this.suspenseConfig = suspenseConfig;
this.action = action;
this.eagerReducer = eagerReducer;
this.eagerState = eagerState;
this.next = next;
}
};

/**
*
* @param {any} action
* @param {boolean} hasEagerState
* @param {any} eagerState
* @param {THookUpdate} next
* @returns hookUpdate
*/
const createHookUpdate = (expirationTime, suspenseConfig, action, eagerReducer, eagerState, next) => {
return new hookUpdate(expirationTime, suspenseConfig, action, eagerReducer, eagerState, next);
};

export default createHookUpdate;
29 changes: 29 additions & 0 deletions srcs/hooks/constructor/hookUpdateQueue.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
/**
*
* @param {THookUpdate} last
* @param {Function} dispatch
* @param {Function} lastRenderedReducer
* @param {any} lastRenderedState
*/
const hookUpdateQueue = class {
constructor(last, dispatch, lastRenderedReducer, lastRenderedState) {
this.last = last;
this.dispatch = dispatch;
this.lastRenderedReducer = lastRenderedReducer;
this.lastRenderedState = lastRenderedState;
}
};

/**
*
* @param {THookUpdate}last
* @param {Function} dispatch
* @param {Function} lastRenderedReducer
* @param {any} lastRenderedState
* @returns
*/
const createHookUpdateQueue = (last, dispatch, lastRenderedReducer, lastRenderedState) => {
return new hookUpdateQueue(last, dispatch, lastRenderedReducer, lastRenderedState);
};

export default createHookUpdateQueue;
6 changes: 6 additions & 0 deletions srcs/hooks/constructor/index.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
import createHookUpdate from "./hookUpdate.js";
import createHookObject from "./hookObject.js";
import createHookUpdateQueue from "./hookUpdateQueue.js";
import createEffect from "./effect.js";

export { createHookUpdate, createHookObject, createHookUpdateQueue, createEffect };
Loading