-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add hooks entry #550
Conversation
Note Currently processing new changes in this PR. This may take a few minutes, please wait... Files selected for processing (1)
WalkthroughThe recent updates primarily focus on refactoring and reorganizing dependencies and imports across multiple packages. Key changes include the removal and addition of dependencies in Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant Component
participant Hook
participant TinyEngineEntry
User->>Component: Interacts with UI
Component->>Hook: Calls useProperty()
Hook->>TinyEngineEntry: Imports getProperty from @opentiny/tiny-engine-entry
TinyEngineEntry-->>Hook: Returns getProperty function
Hook-->>Component: Provides properties via getProperty
Component-->>User: Updates UI with properties
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
0c7cf0a
to
968ec04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Outside diff range and nitpick comments (7)
packages/controller/js/preview.js (1)
Line range hint
31-31
: Optimize the use of spread syntax in the accumulator within thereduce
function.- params.scripts = scripts - .filter((item) => item.script) - .reduce((pre, cur) => ({ ...pre, [cur.package]: cur.script }), {}) + params.scripts = scripts + .filter((item) => item.script) + .reduce((pre, cur) => { pre[cur.package] = cur.script; return pre; }, {})packages/controller/src/hooks/useProperty.js (1)
16-16
: Ensure consistent import ordering and grouping.Consider grouping all imports from
@opentiny/tiny-engine-entry
together for better readability and maintainability.packages/controller/src/hooks/useLayout.js (1)
15-15
: Ensure consistent import ordering and grouping.Consider grouping all imports from
@opentiny/tiny-engine-entry
together for better readability and maintainability.packages/controller/src/hooks/useDataSource.js (1)
17-18
: Ensure consistent import ordering and grouping.Consider grouping all imports from
@opentiny/tiny-engine-entry
together for better readability and maintainability.packages/controller/src/hooks/useCanvas.js (1)
16-16
: Ensure consistent import ordering and grouping.Consider grouping all imports from
@opentiny/tiny-engine-entry
together for better readability and maintainability.packages/controller/js/completion.js (1)
Line range hint
85-91
: Optimize array transformations by using.flatMap()
instead of.map().flat()
.- .map().flat() + .flatMap()Also applies to: 96-99, 122-132
packages/controller/src/hooks/useResource.js (1)
Line range hint
433-434
: Avoid using spread syntax on accumulators due to performance concerns.- resState.componentsMap = appData.componentsMap?.reduce((componentsMap, component) => { - if (component.dependencies) { - getBlockDeps(component.dependencies) - } - return { ...componentsMap, [component.componentName]: component } - }, {}) + resState.componentsMap = appData.componentsMap?.reduce((componentsMap, component) => { + if (component.dependencies) { + getBlockDeps(component.dependencies) + } + componentsMap[component.componentName] = component; + return componentsMap; + }, {})
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (27)
- designer-demo/package.json (1 hunks)
- packages/canvas/src/components/container/shortCutPopover.vue (1 hunks)
- packages/common/package.json (1 hunks)
- packages/controller/js/canvas.js (1 hunks)
- packages/controller/js/completion.js (1 hunks)
- packages/controller/js/http.js (1 hunks)
- packages/controller/js/preview.js (1 hunks)
- packages/controller/src/hooks/mountHooks.js (1 hunks)
- packages/controller/src/hooks/useApp.js (2 hunks)
- packages/controller/src/hooks/useBlock.js (2 hunks)
- packages/controller/src/hooks/useBreadcrumb.js (2 hunks)
- packages/controller/src/hooks/useCanvas.js (2 hunks)
- packages/controller/src/hooks/useDataSource.js (2 hunks)
- packages/controller/src/hooks/useEditorInfo.js (2 hunks)
- packages/controller/src/hooks/useHelp.js (2 hunks)
- packages/controller/src/hooks/useHistory.js (2 hunks)
- packages/controller/src/hooks/useLayout.js (2 hunks)
- packages/controller/src/hooks/usePage.js (2 hunks)
- packages/controller/src/hooks/useProperties.js (3 hunks)
- packages/controller/src/hooks/useProperty.js (3 hunks)
- packages/controller/src/hooks/useResource.js (2 hunks)
- packages/controller/src/hooks/useSaveLocal.js (2 hunks)
- packages/controller/src/hooks/useTranslate.js (2 hunks)
- packages/controller/src/index.js (2 hunks)
- packages/entry/src/hooks.js (1 hunks)
- packages/entry/src/index.js (1 hunks)
- packages/settings/props/src/Main.vue (1 hunks)
Files skipped from review due to trivial changes (4)
- designer-demo/package.json
- packages/common/package.json
- packages/controller/src/hooks/mountHooks.js
- packages/entry/src/index.js
Additional context used
Biome
packages/controller/js/preview.js
[error] 31-31: Avoid the use of spread (
...
) syntax on accumulators. (lint/performance/noAccumulatingSpread)Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.packages/controller/src/hooks/useProperties.js
[error] 219-222: Change to an optional chain. (lint/complexity/useOptionalChain)
Unsafe fix: Change to an optional chain.
packages/controller/js/completion.js
[error] 85-91: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
[error] 96-99: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
[error] 122-132: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
packages/controller/src/hooks/useResource.js
[error] 433-434: Avoid the use of spread (
...
) syntax on accumulators. (lint/performance/noAccumulatingSpread)Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.
GitHub Check: push-check
packages/controller/src/hooks/useProperty.js
[failure] 26-26:
'addPropertyLinks' was used before it was defined
Additional comments not posted (30)
packages/controller/src/hooks/useHelp.js (1)
13-13
: Ensure thatHOOK_NAME.useHelp
is correctly defined in@opentiny/tiny-engine-entry
.packages/controller/js/canvas.js (1)
14-14
: Ensure thatuseEditorInfo
anduseResource
are correctly exported from@opentiny/tiny-engine-entry
and that their usage here aligns with their intended API.Verification successful
The functions
useEditorInfo
anduseResource
are correctly exported frompackages/entry/src/hooks.js
. The import statement incanvas.js
is valid.
packages/entry/src/hooks.js
:
export const useEditorInfo = () => hooksState[HOOK_NAME.useEditorInfo]
export const useResource = () => hooksState[HOOK_NAME.useResource]
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct export and API usage of `useEditorInfo` and `useResource`. # Test: Search for the export statements and API documentation. Expect: Correct export and API usage. ast-grep --lang javascript --pattern $'export { $$$ useEditorInfo, useResource $$$ }' src/@opentiny/tiny-engine-entry/index.jsLength of output: 215
Script:
#!/bin/bash # Description: Locate the correct file that exports `useEditorInfo` and `useResource`. # Search for the export statements of `useEditorInfo` and `useResource` across the entire repository. ast-grep --lang javascript --pattern $'export { $$$ useEditorInfo $$$ }' ast-grep --lang javascript --pattern $'export { $$$ useResource $$$ }'Length of output: 145
Script:
#!/bin/bash # Description: Locate any export statements involving `useEditorInfo` and `useResource` across the entire repository. # Search for any export statements involving `useEditorInfo` and `useResource`. rg 'export.*useEditorInfo' --glob '*.js' rg 'export.*useResource' --glob '*.js'Length of output: 277
packages/settings/props/src/Main.vue (1)
26-26
: Ensure that thegetProperty
method is correctly implemented inuseProperty
and that it handles thepageState
correctly.Verification successful
The
getProperty
method inuseProperty
correctly handles thepageState
parameter. It computes properties based on thepageState
and includes logic for resetting and finding linked properties.
- The
getProperty
method is defined as a constant and usespageState
to compute properties.- It includes calls to
resetLink
,findLinked
, and usesgetBlockProperties
andgetCurrentBlock
fromuseBlock
.This confirms that the method is implemented correctly and handles
pageState
as expected.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct implementation and handling of `getProperty` in `useProperty`. # Test: Search for the implementation of `getProperty`. Expect: Correct handling of `pageState`. ast-grep --lang javascript --pattern $'export default () => { $$$ getProperty($_) { $$$ } $$$ }' src/@opentiny/tiny-engine-controller/hooks/useProperty.jsLength of output: 260
Script:
#!/bin/bash # Description: Locate the correct file containing the `useProperty` hook and verify the implementation of `getProperty`. # Step 1: Locate the file containing `useProperty`. fd 'useProperty' --type f # Step 2: Search for the implementation of `getProperty` within the located file. ast-grep --lang javascript --pattern $'export default () => { $$$ getProperty($_) { $$$ } $$$ }' $(fd 'useProperty' --type f)Length of output: 240
Script:
#!/bin/bash # Description: Extract the implementation of the `getProperty` method from the located file. # Extract the `getProperty` method implementation from `packages/controller/src/hooks/useProperty.js`. ast-grep --lang javascript --pattern $'getProperty($_) { $$$ }' packages/controller/src/hooks/useProperty.jsLength of output: 555
Script:
#!/bin/bash # Description: Extract the implementation of the `getProperty` method from the located file. # Corrected pattern to extract the `getProperty` method implementation from `packages/controller/src/hooks/useProperty.js`. ast-grep --lang javascript --pattern $'function getProperty($_) { $$$ }' packages/controller/src/hooks/useProperty.jsLength of output: 118
Script:
#!/bin/bash # Description: Search for any occurrence of `getProperty` within the located file to understand its definition. # Search for `getProperty` within `packages/controller/src/hooks/useProperty.js`. rg 'getProperty' packages/controller/src/hooks/useProperty.jsLength of output: 155
Script:
#!/bin/bash # Description: Extract the full implementation of the `getProperty` constant from the located file. # Extract the full implementation of the `getProperty` constant from `packages/controller/src/hooks/useProperty.js`. sed -n '/const getProperty =/,/};/p' packages/controller/src/hooks/useProperty.jsLength of output: 728
packages/controller/src/hooks/useBreadcrumb.js (1)
14-14
: Ensure thatHOOK_NAME.useBreadcrumb
is correctly defined in@opentiny/tiny-engine-entry
.Verification successful
The
HOOK_NAME.useBreadcrumb
is correctly defined in thepackages/entry/src/hooks.js
file.
packages/entry/src/hooks.js:export const HOOK_NAME = { ... [HOOK_NAME.useBreadcrumb]: {}, ... }
packages/entry/src/hooks.js:export const useBreadcrumb = () => hooksState[HOOK_NAME.useBreadcrumb]
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and correct definition of `HOOK_NAME.useBreadcrumb` in the module. # Test: Search for the definition of `HOOK_NAME.useBreadcrumb`. Expect: Definition exists and is correct. ast-grep --lang javascript --pattern $'export const HOOK_NAME = { $$$ useBreadcrumb: $_ $$$ }' src/@opentiny/tiny-engine-entry/hooks.jsLength of output: 224
Script:
#!/bin/bash # Description: Locate the file containing the definition of `HOOK_NAME` and verify the presence of `useBreadcrumb`. # Step 1: Locate the file containing `HOOK_NAME`. fd 'HOOK_NAME' --type f # Step 2: Verify the definition of `useBreadcrumb` in the located file. ast-grep --lang javascript --pattern $'export const HOOK_NAME = { $$$ useBreadcrumb: $_ $$$ }' $(fd 'HOOK_NAME' --type f)Length of output: 144
Script:
#!/bin/bash # Description: Locate the file containing the definition of `HOOK_NAME` and verify the presence of `useBreadcrumb`. # Step 1: Locate the file containing `HOOK_NAME`. rg 'HOOK_NAME' --type js # Step 2: Verify the definition of `useBreadcrumb` in the located file. ast-grep --lang javascript --pattern $'export const HOOK_NAME = { $$$ useBreadcrumb: $_ $$$ }' $(rg --files-with-matches 'HOOK_NAME' --type js)Length of output: 6210
packages/controller/src/index.js (3)
21-22
: Verify thatuseNotify
anduseModal
are correctly implemented in thecomponents
directory.Verification successful
The
useNotify
anduseModal
implementations have been verified and are correctly implemented in thecomponents
directory.
useNotify
is implemented in./packages/controller/src/components/useNotify.jsx
.useModal
is implemented in./packages/controller/src/components/useModal.jsx
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct implementation of `useNotify` and `useModal`. # Test: Search for the implementation of `useNotify` and `useModal`. ast-grep --lang javascript --pattern $'import $$$ from "./components/useNotify"' ast-grep --lang javascript --pattern $'import $$$ from "./components/useModal"'Length of output: 344
Script:
#!/bin/bash # Description: Locate and inspect the implementation of `useNotify` and `useModal`. # Locate the files fd 'useNotify.js' ./packages/controller/src/components fd 'useModal.js' ./packages/controller/src/components # Inspect the contents of the files cat $(fd 'useNotify.js' ./packages/controller/src/components) cat $(fd 'useModal.js' ./packages/controller/src/components)Length of output: 2363
41-43
: Ensure that all hooks imported from@opentiny/tiny-engine-entry
are correctly initialized and used.
14-14
: Check ifuseMessage
is properly imported and utilized.packages/controller/src/hooks/useApp.js (2)
76-81
: Verify thatinitHook
is correctly used to initializeuseApp
with the appropriate parameters.Verification successful
The verification confirms that
initHook
is correctly used to initializeuseApp
with the appropriate parameters.
initHook
is defined in./packages/entry/src/hooks.js
and is used correctly.HOOK_NAME.useApp
is a valid hook name defined in./packages/entry/src/hooks.js
.- The parameters
appInfoState
,fetchAppInfo
,fetchAppList
, andupdateApp
are correctly defined in./packages/controller/src/hooks/useApp.js
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct usage of `initHook` for `useApp`. # Test: Search for the usage of `initHook` with `useApp`. ast-grep --lang javascript --pattern $'initHook(HOOK_NAME.useApp, { $$$ })'Length of output: 438
Script:
#!/bin/bash # Description: Verify the definitions and usages of `initHook`, `HOOK_NAME.useApp`, and the parameters. # Search for the definition of `initHook`. ast-grep --lang javascript --pattern $'function initHook($_, $_) { $$$ }' # Search for the definition of `HOOK_NAME.useApp`. ast-grep --lang javascript --pattern $'const HOOK_NAME = { $$$ useApp: $_, $$$ }' # Search for the definitions of `appInfoState`, `fetchAppInfo`, `fetchAppList`, and `updateApp`. ast-grep --lang javascript --pattern $'const appInfoState = $_' ast-grep --lang javascript --pattern $'const fetchAppInfo = $_' ast-grep --lang javascript --pattern $'const fetchAppList = $_' ast-grep --lang javascript --pattern $'const updateApp = $_'Length of output: 2659
15-15
: Ensure thatHOOK_NAME
andinitHook
are correctly imported from@opentiny/tiny-engine-entry
.packages/controller/src/hooks/useEditorInfo.js (2)
74-79
: Verify thatinitHook
is correctly used to initializeuseEditorInfo
with the appropriate parameters.Verification successful
The verification process confirms that
initHook
is correctly used to initializeuseEditorInfo
with the appropriate parameters. Here are the details:
initHook
is defined inpackages/entry/src/hooks.js
and accepts a hook name and hook content.HOOK_NAME.useEditorInfo
is defined as'editorInfo'
in the same file.- The parameters
_getWebData
,getUserInfo
,userInfo
, andisAdmin
are all defined inpackages/controller/src/hooks/useEditorInfo.js
.Thus, the usage of
initHook
withuseEditorInfo
is correct.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct usage of `initHook` for `useEditorInfo`. # Test: Search for the usage of `initHook` with `useEditorInfo`. ast-grep --lang javascript --pattern $'initHook(HOOK_NAME.useEditorInfo, { $$$ })'Length of output: 495
Script:
#!/bin/bash # Find the definition of `initHook` ast-grep --lang javascript --pattern 'function initHook($_, $_) { $$$ }' # Find the definition of `HOOK_NAME.useEditorInfo` ast-grep --lang javascript --pattern 'const HOOK_NAME = { $$$ useEditorInfo: $_, $$$ }' # Find the definitions of `_getWebData`, `getUserInfo`, `userInfo`, and `isAdmin` rg '_getWebData|getUserInfo|userInfo|isAdmin'Length of output: 3309
15-15
: Ensure thatHOOK_NAME
andinitHook
are correctly imported from@opentiny/tiny-engine-entry
.packages/controller/js/preview.js (1)
15-15
: Ensure thatuseResource
is correctly imported from@opentiny/tiny-engine-entry
.packages/controller/js/http.js (1)
14-14
: Update import paths to use centralized hook definitions.Ensure that the new import paths are correctly configured in the project settings to avoid module resolution errors.
Also applies to: 17-17
packages/entry/src/hooks.js (1)
1-62
: Centralize hook definitions and state management.This change centralizes the definitions and state management of hooks, which can improve maintainability and reduce redundancy. Ensure that all dependent modules are updated to use these centralized hooks.
packages/controller/src/hooks/useHistory.js (1)
126-132
: Initialize useHistory hook with necessary functions.This initialization ensures that all necessary functions are available for the useHistory hook. Verify that all functions are correctly implemented and that there are no side effects from this initialization.
packages/controller/src/hooks/useSaveLocal.js (1)
87-90
: Properly initialize useSaveLocal hook with its functions.The initialization of the useSaveLocal hook with its functions ensures that all necessary functionalities are encapsulated within the hook. Confirm that the functions
confirmSaveLocal
andsavePageLocal
handle all edge cases and errors appropriately.packages/controller/src/hooks/useProperty.js (1)
97-101
: Verify the hook initialization parameters.Verification successful
The search results indicate that
initHook(HOOK_NAME.useProperty, { getProperty })
is indeed present in the codebase, specifically inpackages/controller/src/hooks/useProperty.js
. This confirms thatgetProperty
is being initialized correctly within theuseProperty
hook.
packages/controller/src/hooks/useProperty.js:initHook(HOOK_NAME.useProperty, { getProperty })
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `getProperty` is correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type python $'initHook(HOOK_NAME.useProperty, { getProperty })'Length of output: 234
Script:
#!/bin/bash # Description: Verify that `getProperty` is correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type js 'initHook\(HOOK_NAME\.useProperty, \{ getProperty \}\)'Length of output: 70
Script:
#!/bin/bash # Description: Search for all instances of `initHook` and `HOOK_NAME.useProperty` in the codebase. # Test 1: Search for all instances of `initHook` to understand its usage. rg 'initHook' # Test 2: Search for all instances of `HOOK_NAME.useProperty` to see how it is referenced. rg 'HOOK_NAME\.useProperty'Length of output: 3217
packages/controller/src/hooks/useLayout.js (1)
145-159
: Verify the hook initialization parameters.Verification successful
The
initHook
function call with the specified parameters is correctly found in theuseLayout.js
file at the expected lines. This confirms that the hook initialization parameters are correctly set up in the code.
- Location:
packages/controller/src/hooks/useLayout.js
lines 145-159Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type python $'initHook(HOOK_NAME.useLayout, { PLUGIN_NAME, activeSetting, activePlugin, closePlugin, layoutState, getScale, setDimension, getDimension, registerPluginApi, getPluginApi, getPluginState, pluginState, isEmptyPage })'Length of output: 564
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage using ast-grep. Expect: Proper initialization with correct parameters. ast-grep --lang javascript --pattern $'initHook(HOOK_NAME.useLayout, { PLUGIN_NAME, activeSetting, activePlugin, closePlugin, layoutState, getScale, setDimension, getDimension, registerPluginApi, getPluginApi, getPluginState, pluginState, isEmptyPage })'Length of output: 1257
packages/controller/src/hooks/useDataSource.js (1)
123-123
: Verify the hook initialization parameters.Verification successful
The initialization parameters for the
useDataSource
hook appear to be correctly defined and used within theuseDataSource.js
file. ThedataSourceState
,compareData
, andsaveDataSource
are all properly declared and utilized in the context of the hook.
dataSourceState
is defined as a reactive object.compareData
is a function that compares various states withindataSourceState
.saveDataSource
is a function that utilizescompareData
anddataSourceState
.These parameters are correctly passed to the
initHook
function.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type python $'initHook(HOOK_NAME.useDataSource, { dataSourceState, compareData, saveDataSource })'Length of output: 306
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type js 'initHook\(HOOK_NAME\.useDataSource, \{ dataSourceState, compareData, saveDataSource \}\)'Length of output: 236
Script:
#!/bin/bash # Description: Verify the definitions and usages of dataSourceState, compareData, and saveDataSource in the useDataSource.js file. # Test: Search for the definitions and usages of dataSourceState, compareData, and saveDataSource. rg 'dataSourceState|compareData|saveDataSource' packages/controller/src/hooks/useDataSource.jsLength of output: 1954
packages/controller/src/hooks/useCanvas.js (1)
170-188
: Verify the hook initialization parameters.Verification successful
The verification process confirms that all the parameters used in the
initHook
call are correctly initialized and utilized in other parts of the application. Here are the findings for each parameter:
pageState
: Found in multiple files, indicating its widespread use.isBlock
: Found in several files, confirming its initialization and usage.isSaved
: Found in multiple files, confirming its initialization and usage.isLoading
: Found in several files, confirming its initialization and usage.initData
: Found in multiple files, confirming its initialization and usage.setSaved
: Found in several files, confirming its initialization and usage.clearCanvas
: Found in multiple files, confirming its initialization and usage.getPageSchema
: Found in several files, confirming its initialization and usage.resetPageCanvasState
: Found in multiple files, confirming its initialization and usage.resetBlockCanvasState
: Found in several files, confirming its initialization and usage.clearCurrentState
: Found in multiple files, confirming its initialization and usage.getCurrentSchema
: Found in several files, confirming its initialization and usage.setCurrentSchema
: Found in multiple files, confirming its initialization and usage.getCurrentPage
: Found in several files, confirming its initialization and usage.initCanvasApi
: Found in multiple files, confirming its initialization and usage.canvasApi
: Found in several files, confirming its initialization and usage.isCanvasApiReady
: Found in multiple files, confirming its initialization and usage.Based on these findings, the hook initialization parameters are correctly set up and used throughout the codebase.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg --type python $'initHook(HOOK_NAME.useCanvas, { pageState, isBlock, isSaved, isLoading, initData, setSaved, clearCanvas, getPageSchema, resetPageCanvasState, resetBlockCanvasState, clearCurrentState, getCurrentSchema, setCurrentSchema, getCurrentPage, initCanvasApi, canvasApi, isCanvasApiReady })'Length of output: 698
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test: Search for the initialization usage. Expect: Proper initialization with correct parameters. rg 'initHook\(HOOK_NAME\.useCanvas, \{ pageState, isBlock, isSaved, isLoading, initData, setSaved, clearCanvas, getPageSchema, resetPageCanvasState, resetBlockCanvasState, clearCurrentState, getCurrentSchema, setCurrentSchema, getCurrentPage, initCanvasApi, canvasApi, isCanvasApiReady \}\)'Length of output: 293
Script:
#!/bin/bash # Description: Verify that all functions and states are correctly initialized in other parts of the application. # Test 1: Search for the initialization usage with a broader pattern. rg 'initHook\(HOOK_NAME\.useCanvas, \{.*\}\)' # Test 2: Search for individual parameters to confirm their presence and usage. for param in pageState isBlock isSaved isLoading initData setSaved clearCanvas getPageSchema resetPageCanvasState resetBlockCanvasState clearCurrentState getCurrentSchema setCurrentSchema getCurrentPage initCanvasApi canvasApi isCanvasApiReady; do echo "Searching for parameter: $param" rg $param doneLength of output: 46973
packages/canvas/src/components/container/shortCutPopover.vue (1)
44-44
: UpdateduseProperty
usage to match new hook API.packages/controller/src/hooks/usePage.js (1)
150-162
: Proper initialization ofusePage
hook with relevant states and functions.packages/controller/src/hooks/useProperties.js (1)
222-232
: Proper initialization ofuseProperties
hook with relevant functions.packages/controller/js/completion.js (1)
13-13
: Updated import paths to use new hooks.packages/controller/src/hooks/useTranslate.js (2)
256-271
: Initialization ofuseTranslate
hook looks comprehensive and well-structured.
16-20
: Ensure the updated relative paths in imports are correct.Verification successful
The updated relative paths in the import statements are correct based on the search results.
../../js/environments
matchespackages/controller/js/environments.js
../../js/vscodeGenerateFile
matchespackages/controller/js/vscodeGenerateFile.js
../../utils
matchespackages/controller/utils.js
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist. fd --type file 'environments.js' 'js' fd --type file 'vscodeGenerateFile.js' 'js' fd --type file 'utils.js' 'utils'Length of output: 382
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist by searching the entire repository. fd --type file 'environments.js' fd --type file 'vscodeGenerateFile.js' fd --type file 'utils.js'Length of output: 491
packages/controller/src/hooks/useResource.js (2)
483-500
: Initialization ofuseResource
hook looks comprehensive and well-structured.
14-30
: Ensure the updated relative paths in imports are correct.Verification successful
The updated relative paths in the imports are correct.
globalConfig.js
exists atpackages/controller/src/globalConfig.js
.canvas.js
exists atpackages/controller/js/canvas.js
.useNotify.js
exists atpackages/controller/src/components/useNotify.jsx
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist. fd --type file 'globalConfig.js' 'globalConfig' fd --type file 'canvas.js' 'js' fd --type file 'useNotify.js' 'components'Length of output: 404
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist. fd --type file 'globalConfig.js' fd --type file 'canvas.js' fd --type file 'useNotify.js'Length of output: 390
packages/controller/src/hooks/useBlock.js (2)
772-815
: Initialization ofuseBlock
hook looks comprehensive and well-structured.
19-31
: Ensure the updated relative paths in imports are correct.Verification successful
The updated relative paths in the imports are correct. The files
canvas.js
,ast.js
,css.js
, andglobalConfig.js
exist in the expected locations within the repository.
canvas.js
: Found atpackages/controller/js/canvas.js
ast.js
: Found atpackages/controller/js/ast.js
css.js
: Found atpackages/controller/js/css.js
globalConfig.js
: Found atpackages/controller/src/globalConfig.js
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist. fd --type file 'canvas.js' 'js' fd --type file 'ast.js' 'js' fd --type file 'css.js' 'js' fd --type file 'globalConfig.js' 'globalConfig'Length of output: 499
Script:
#!/bin/bash # Description: Verify the correctness of the updated relative paths in imports. # Test: Check if the paths exist by searching the entire repository. fd --type file 'canvas.js' fd --type file 'ast.js' fd --type file 'css.js' fd --type file 'globalConfig.js'Length of output: 419
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (3)
packages/controller/js/preview.js (1)
Line range hint
31-31
: Optimize the use of spread syntax in.reduce
to improve performance.- params.scripts = scripts - .filter((item) => item.script) - .reduce((pre, cur) => ({ ...pre, [cur.package]: cur.script }), {}) + const scriptMap = {} + scripts.filter((item) => item.script).forEach((item) => { + scriptMap[item.package] = item.script + }) + params.scripts = scriptMappackages/controller/js/completion.js (1)
Line range hint
85-91
: Consider replacing.map().flat()
with.flatMap()
for better performance and readability.- .map((item) => Object.keys(item.actions).map((name) => `${item.id}.${name}`)).flat() + .flatMap((item) => Object.keys(item.actions).map((name) => `${item.id}.${name}`))Also applies to: 96-99, 122-132
packages/controller/src/hooks/useResource.js (1)
Line range hint
433-434
: Optimize the use of spread syntax in.reduce
.Using spread syntax in accumulators can lead to performance issues due to its
O(n^2)
complexity. Consider using.push
or.splice
instead to improve performance.- return { ...componentsMap, [component.componentName]: component } + componentsMap[component.componentName] = component; + return componentsMap;
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (27)
- designer-demo/package.json (1 hunks)
- packages/canvas/src/components/container/shortCutPopover.vue (1 hunks)
- packages/common/package.json (1 hunks)
- packages/controller/js/canvas.js (1 hunks)
- packages/controller/js/completion.js (1 hunks)
- packages/controller/js/http.js (1 hunks)
- packages/controller/js/preview.js (1 hunks)
- packages/controller/src/hooks/mountHooks.js (1 hunks)
- packages/controller/src/hooks/useApp.js (2 hunks)
- packages/controller/src/hooks/useBlock.js (2 hunks)
- packages/controller/src/hooks/useBreadcrumb.js (2 hunks)
- packages/controller/src/hooks/useCanvas.js (2 hunks)
- packages/controller/src/hooks/useDataSource.js (2 hunks)
- packages/controller/src/hooks/useEditorInfo.js (2 hunks)
- packages/controller/src/hooks/useHelp.js (2 hunks)
- packages/controller/src/hooks/useHistory.js (2 hunks)
- packages/controller/src/hooks/useLayout.js (2 hunks)
- packages/controller/src/hooks/usePage.js (2 hunks)
- packages/controller/src/hooks/useProperties.js (3 hunks)
- packages/controller/src/hooks/useProperty.js (4 hunks)
- packages/controller/src/hooks/useResource.js (2 hunks)
- packages/controller/src/hooks/useSaveLocal.js (2 hunks)
- packages/controller/src/hooks/useTranslate.js (2 hunks)
- packages/controller/src/index.js (2 hunks)
- packages/entry/src/hooks.js (1 hunks)
- packages/entry/src/index.js (1 hunks)
- packages/settings/props/src/Main.vue (1 hunks)
Files skipped from review due to trivial changes (5)
- designer-demo/package.json
- packages/common/package.json
- packages/controller/js/canvas.js
- packages/controller/src/hooks/mountHooks.js
- packages/entry/src/index.js
Additional context used
Biome
packages/controller/js/preview.js
[error] 31-31: Avoid the use of spread (
...
) syntax on accumulators. (lint/performance/noAccumulatingSpread)Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.packages/controller/src/hooks/useProperties.js
[error] 219-222: Change to an optional chain. (lint/complexity/useOptionalChain)
Unsafe fix: Change to an optional chain.
packages/controller/js/completion.js
[error] 85-91: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
[error] 96-99: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
[error] 122-132: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)
Safe fix: Replace the chain with .flatMap().
packages/controller/src/hooks/useResource.js
[error] 433-434: Avoid the use of spread (
...
) syntax on accumulators. (lint/performance/noAccumulatingSpread)Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.
Additional comments not posted (43)
packages/controller/src/hooks/useHelp.js (3)
13-13
: Import statement correctly aligns with the new centralized hook management system.
Line range hint
14-37
: Constants and helper functions are well-defined and correctly implemented.
39-42
: Hook initialization is correctly implemented usinginitHook
with appropriate parameters.packages/settings/props/src/Main.vue (2)
Line range hint
1-25
: Import statements are correctly aligned with the project's structure.
26-26
: The setup function correctly uses the updateduseProperty().getProperty
method.packages/controller/src/hooks/useBreadcrumb.js (3)
14-14
: Import statement correctly aligns with the new centralized hook management system.
Line range hint
15-40
: Constants and helper functions are well-defined and correctly implemented.
42-47
: Hook initialization is correctly implemented usinginitHook
with appropriate parameters.packages/controller/src/index.js (2)
13-22
: Import statements are correctly aligned with the project's structure and the PR's objectives.
41-45
: Export statements are correctly reorganized to align with the centralized management of hooks and utilities.packages/controller/src/hooks/useApp.js (2)
76-81
: Initialization ofuseApp
hook looks correct and well-structured.
15-15
: Ensure proper initialization and usage ofinitHook
.Verification successful
The
initHook
function is used consistently across multiple files in the project. The search results indicate that it is imported and utilized in various hooks, ensuring proper initialization.
packages/controller/src/hooks/useApp.js
packages/controller/src/hooks/useLayout.js
packages/controller/src/hooks/useResource.js
packages/controller/src/hooks/useSaveLocal.js
packages/controller/src/hooks/useTranslate.js
packages/controller/src/hooks/useProperties.js
packages/controller/src/hooks/usePage.js
packages/controller/src/hooks/useHistory.js
packages/controller/src/hooks/useHelp.js
packages/controller/src/hooks/useEditorInfo.js
packages/controller/src/hooks/useDataSource.js
packages/controller/src/hooks/useCanvas.js
packages/controller/src/hooks/useBreadcrumb.js
packages/controller/src/hooks/useBlock.js
packages/controller/src/hooks/useProperty.js
This confirms that the
initHook
function is correctly integrated and used across the project.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `initHook` is used correctly across the project. # Test: Search for `initHook` usage. Expect: Consistent usage across all files. rg --type python $'initHook'Length of output: 58
Script:
#!/bin/bash # Description: Verify that `initHook` is used correctly across the project. # Test: Search for `initHook` usage. Expect: Consistent usage across all files. rg --type js 'initHook'Length of output: 2964
packages/controller/src/hooks/useEditorInfo.js (2)
74-79
: Initialization ofuseEditorInfo
hook looks correct and well-structured.
15-15
: Ensure proper initialization and usage ofinitHook
.Verification successful
The
initHook
function is used consistently across multiple files in the project, includinguseEditorInfo.js
. This indicates that the initialization and usage ofinitHook
are properly integrated.
packages/controller/src/hooks/useEditorInfo.js
:initHook(HOOK_NAME.useEditorInfo, { ... })
The usage pattern matches other instances, confirming that the implementation follows the project's conventions.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `initHook` is used correctly across the project. # Test: Search for `initHook` usage. Expect: Consistent usage across all files. rg --type python $'initHook'Length of output: 58
Script:
#!/bin/bash # Description: Verify that `initHook` is used correctly across the project. # Test: Search for `initHook` usage. Expect: Consistent usage across all files. rg --type js 'initHook'Length of output: 2964
packages/controller/js/preview.js (1)
15-15
: Correct import ofuseResource
aligns with project's new structure.packages/controller/js/http.js (1)
17-17
: Correct import ofusePage
anduseCanvas
aligns with project's new structure.packages/entry/src/hooks.js (3)
1-18
: The constants for hook names are well-defined and cover a comprehensive range of functionalities.
20-37
: Initial states for hooks are appropriately set as empty objects, ready for dynamic assignment.
39-54
: Hook accessor functions are correctly implemented, ensuring each hook can correctly access its designated state.packages/controller/src/hooks/useHistory.js (3)
14-14
: Updated imports to use centralized definitions from@opentiny/tiny-engine-entry
enhance maintainability and reduce duplication.
Line range hint
14-123
: The history management logic is robust, correctly handling state changes and providing necessary navigation functionalities.
126-132
: Proper initialization of theuseHistory
hook with its state and functions ensures it is ready for use across the application.packages/controller/src/hooks/useSaveLocal.js (2)
14-16
: Updated imports to centralize hook definitions align with the project's architectural improvements.
Line range hint
14-90
: The logic for local saving is well-implemented, handling interactions, error responses, and user decisions effectively.packages/controller/src/hooks/useProperty.js (2)
16-16
: Centralizing hook definitions through updated imports enhances maintainability and reduces code duplication.
Line range hint
16-101
: The property management logic is effectively implemented, handling linking and resetting links between properties and blocks with reactivity and integration with block management.packages/controller/src/hooks/useLayout.js (2)
15-15
: Import statement forHOOK_NAME
andinitHook
is correctly added to centralize hook management.
145-159
: Initialization ofuseLayout
hook usinginitHook
correctly encapsulates the hook's functionality and state, aligning with the PR's objectives to centralize hook management.packages/controller/src/hooks/useDataSource.js (2)
17-18
: Import statement forHOOK_NAME
andinitHook
is correctly added to centralize hook management.
122-123
: Initialization ofuseDataSource
hook usinginitHook
correctly encapsulates the hook's functionality and state, aligning with the PR's objectives to centralize hook management.packages/controller/src/hooks/useCanvas.js (2)
16-16
: Import statement forHOOK_NAME
,initHook
, anduseHistory
is correctly added to centralize hook management.
169-188
: Initialization ofuseCanvas
hook usinginitHook
correctly encapsulates the hook's functionality and state, aligning with the PR's objectives to centralize hook management.packages/canvas/src/components/container/shortCutPopover.vue (1)
44-44
: Update in property access method aligns with the PR's objectives to standardize hook usage across the project.packages/controller/src/hooks/usePage.js (2)
15-15
: Import change aligns with project restructuring.
150-162
: Hook initialization correctly encapsulates the necessary states and functions.packages/controller/src/hooks/useProperties.js (2)
15-15
: Import change aligns with project restructuring.
222-232
: Hook initialization correctly encapsulates the necessary states and functions.packages/controller/js/completion.js (1)
13-13
: Import change aligns with project restructuring.packages/controller/src/hooks/useTranslate.js (2)
16-20
: Import change aligns with project restructuring.
256-271
: Hook initialization correctly encapsulates the necessary states and functions.packages/controller/src/hooks/useResource.js (2)
14-30
: Refactor imports to use centralized entry point.The refactoring of imports to use
@opentiny/tiny-engine-entry
centralizes the management of hooks and utilities, which is a good practice for maintainability and modularity.
482-500
: Ensure proper initialization ofuseResource
hook.The initialization of the
useResource
hook with all necessary functions and state encapsulated is a good practice. It ensures that all functionalities are properly managed and accessible through the hook.packages/controller/src/hooks/useBlock.js (1)
771-815
: Ensure proper initialization ofuseBlock
hook.The comprehensive initialization of the
useBlock
hook with all block-related functionalities ensures that the block management is centralized and modular, which is beneficial for maintainability and scalability.
* feat: add hooks api in entry
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Refactor
New Features
Chores