English 中文(简体)
SolidJS setStore is Applying to All Properties Rather than only the Specified Path
原标题:

First time asking a question here so please be gentle.

I m attempting to set a specific object within a store with a reference to a callback, but rather than only setting that specific object s callback, it s setting the callback for all objects along a similar path in the store.

Relevant function:

const registerActionCallback = (
    on:  Use  |  Combo ,
    actionName: string,
    cbKey: string,
    cb: (fns: ControllerActionFns) => void
) => {
    setState(
     actionPool , // Record<string, Action>
    actionName, // string
    `on${on}Callbacks`, // Record<string, fn>, property of Action object
        cbKey,
        (_: (fns: ControllerActionFns) => void) => cb
    );
};

Example State:

const [state, setState] = createStore({
    actionPool: {
        A: {...},
        ...,
        M: {
            ...,
            onUseCallbacks: {} // initially empty
            onComboCallbacks: {} // initially empty
            ...,
        },
        ...,
        Z: {...},
    },
    ...,
});

The idea is I have a series of actions (buttons) that, when pressed, should run a series of callbacks that are located in either onUseCallbacks or onComboCallbacks , which are objects to make deregistering convenient.

So, let s say I have actions A through Z, but I want to register callback testCB , which logs hello , with action M on Use.

The function will then run: setState( actionPool , M , onUseCallbacks , testCB , () => () => console.log( hello ))

The obvious expectation is that only clicking the button tied to action M would log hello , except, clicking any button tied to any action in the actionPool A through Z will log hello .

I can t for the life of me figure out what would be causing this so any insight would be greatly appreciated. Never experienced this issue despite using setStore in similar ways constantly, although this may be the first time I ve tried setting callbacks using setStore.

Edit:

The way the callbacks are being called: A reference to the pressed action is passed into a fireAction function which runs:

for (const key in action.onUseCallbacks) 
    action.onUseCallbacks[key]();
问题回答

暂无回答




相关问题
Calling a service from a callback method in Client

I have a scenario where, upon receiving a command on one of the callback methods in client, the client needs to call another service. For example: In OnNewCommand() callback method client receives a ...

ASP.NET UpdatePanel Javascript Callback

I came across this issue recently and thought it was really helpful. My question was, how would you call a piece of javascript after an updatepanel loads via AJAX in ASP.NET? I needed to reinitialize ...

WCF duplex channel gets closed when using callbacks

My WCF service uses netTcpBinding, and has a callback object. I need to service multiple concurrent clients, and mantain sessions, so the service is decorated with [ServiceBehavior(...

C++: static function wrapper that routes to member function?

I ve tried all sorts of design approaches to solve this problem, but I just can t seem to get it right. I need to expose some static functions to use as callback function to a C lib. However, I want ...

getJSON callback not happening

I have looked at similar queries here, but I can t seem to apply them to my problem. I am pretty new to jquery, so I may be doing something dumb. I have a simple getJSON test: $(document).ready(...

热门标签