Skip to content

Commit

Permalink
Merge pull request #64 from Tresjs/bugfix/62-leches-controls-multiply…
Browse files Browse the repository at this point in the history
…-when-page-is-revisited-in-cientos-docs

fix: remove unique key generation on controls duplicated outside of f…
  • Loading branch information
alvarosabu authored Nov 3, 2023
2 parents 67b0e7b + ab1ce23 commit c419049
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
6 changes: 1 addition & 5 deletions playground/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const { test, awiwi } = useControls({ test: true, awiwi: 'awiwi' })
console.log('test', test)
console.log('awiwi', awiwi)
useControls({
api: true
})
/* watchEffect(() => {
console.log('test', test.value)
})
Expand Down Expand Up @@ -114,7 +110,7 @@ const { visible } = useControls({
console.log('visible', visible.value)
}) */
useControls('Folder', {
useControls('Folder', {
pepe: true,
slider: {
value: 0.5,
Expand Down
18 changes: 0 additions & 18 deletions src/composables/useControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ export const dispose = (uuid: string = DEFAULT_UUID): void => {
}
}

// Helper function to generate a unique key
const generateUniqueKey = (baseKey: string, controls: any): string => {
let suffix = 1
let newKey = `${baseKey}_${suffix}`

while (controls[newKey]) {
suffix++
newKey = `${baseKey}_${suffix}`
}

return newKey
}

// eslint-disable-next-line max-len
export const useControls = (
folderNameOrParams: string | { [key: string]: any },
Expand Down Expand Up @@ -113,11 +100,6 @@ export const useControls = (
if (folderName) {
uniqueKey = `${folderName}${key.charAt(0).toUpperCase() + key.slice(1)}`
}
// If the control is not part of a folder and a control with the same key already exists,
// append a numerical suffix to the key
if (!folderName && controls[uniqueKey]) {
uniqueKey = generateUniqueKey(key, controls)
}

// If the value is an object with control options
if (typeof value === 'object' && !isRef(value) && !Array.isArray(value) && value.value !== undefined) {
Expand Down
Loading

0 comments on commit c419049

Please sign in to comment.