letoast
letoast
Explore posts from servers
NNuxt
Created by letoast on 4/17/2024 in #❓・help
Adding to composable using a Layer
What would be the best way to add to a composable using layers? For example, I have my base layer with /composables/useXY.ts which has for example:
// layers/base/composables/useXY.ts
export default function () {
return {
get: () => {},
post: () => {}
}
}
// layers/base/composables/useXY.ts
export default function () {
return {
get: () => {},
post: () => {}
}
}
and I'd like to extend this composable's functionality with another method. I'd like to use layers to do this. If I define this same composable with just the added method in another layer, it just overrides the original one:
// layers/anotherLayer/composables/useXY.ts
export default function () {
return {
delete: () => {},
}
}
// layers/anotherLayer/composables/useXY.ts
export default function () {
return {
delete: () => {},
}
}
What would be the correct way to do this? The final composable should look like:
export default function () {
return {
get: () => {},
post: () => {},
delete: () => {} // Added in another layer
}
}
export default function () {
return {
get: () => {},
post: () => {},
delete: () => {} // Added in another layer
}
}
32 replies