Accessing original action function #1695
-
Hi there👋🏻 We are currently developing a plugin for Pinia, integrating it with a not-yet-released Offline First library. Now, using the plugin, actions in the store can be wrapped so they go through a queue and are only executed when there's network connectivity. The API could look something like that: actions: {
doSomething: queueAction({
mutation () {
// mutation that is tied to action
},
handler () {
// do something...
}
})
} We need to save some context here, that's why the const fn = function () {
// wrapper logic
}
Object.defineProperty(fn, 'originalFn', {
value: opts.handler,
writable: true,
enumerable: false,
configurable: false
})
return fn Here's the problem though: when i try to access the action function in Pinia like this: const fn = store[actionName] ...i only get back a wrapped function call, not the original function. This way i can't access the property descriptors i set. Hence the question: is there any way i could access the original action function through the Pinia store? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unfortunately, I don't think this is feasible because even if we add the original fn to the wrapped action, nothing prevents plugins from wrapping the action again and erasing that. |
Beta Was this translation helpful? Give feedback.
Unfortunately, I don't think this is feasible because even if we add the original fn to the wrapped action, nothing prevents plugins from wrapping the action again and erasing that.
Maybe passing the original
action
function to$onAction()
could work out for your particular case but I think it would just look confusing ("why do we have access toaction
here") for most users