ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
7.96k stars 1.95k forks source link

Adding new withMethods causes NgRx signal store to return store: {[p:string]: function():?) #4347

Closed dreamstar-enterprises closed 1 month ago

dreamstar-enterprises commented 1 month ago

Which @ngrx/* package(s) are the source of the bug?

store

Minimal reproduction of the bug/regression with instructions

Hi,

I have a signal store. Its fairly long

It has:

   withState(initialState),

  withNetworkAPIServices(),

  withExtraStoreServices(),

  withMethods((store) => {...})

  withComputed((store) => {...})

  withMethods((store) => {...}) --> all fine upto this point

  withMethods((store) => {}) --> adding another withMethods (even it is blank) causes the below:

Not sure why this is.. I'm just adding another empty withMethods((store) => {})

Sachin

Expected behavior

Should just be possible to add another withMethods

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

NgRx Signal Stores JetBrains Ultimate

Other information

No response

I would be willing to submit a PR to fix this issue

jyjor commented 1 month ago

I have seen this same problem before when a previous with*** function had an error in it. In my case, there was no TypeScript error and the only indication that something was wrong was that the store stopped working. Assuming you are experiencing the same thing, try commenting out the withMethods((store) => {...}) --> all fine upto this point function call, and check to see if the store in the final withMethods then works. If it does, you should be able to incrementally uncomment code until you can isolate the exact spot that is causing the error.

timdeschryver commented 1 month ago

Please provide a reproduction, otherwise we won't be able to investigate this.

store in the method returns store: {[p:string]: function():?)

Side note, this returns a void, while withMethods expects an object.

// returns void
withMethods((store) => {})

// add braces to return an empty object
withMethods((store) => ({}))

I have a signal store. Its fairly long

The underlying issue might be related to #4314

markostanimirovic commented 1 month ago

Feel free to reopen this issue with the provided reproduction.

dreamstar-enterprises commented 1 month ago

Hi Mark,

I think I hit some sort of limit, as I ended up spliting the store into two, and it worked without any problems (about 5 withStatements... in each)

I think there have been some suggestions for adding some kind of builder method, but I'm very happy so far with my NgRx experience so far. It's completely organised my code base (for variables)

The NgRx documentation is also very good.

My only feedback perhaps would be some examples on deep signals, as I had problems using the inbuilt Entity method, and ended up creating my own deep signalled Map property, that had dynamic keys, and with them objects as values.

Apart from that, I'm happy so far.

Cheers