zuriscript/signalstory

Computed signal does not work for arrays [Bug report]

DruidNx opened this issue · 2 comments

Is this a regression?

Yes

Description

I tried adding the following computed signal to the sample app

// books.store.ts
public hasMorethanOneBook() {
    return computed(() => this.state().length > 1)
  }

then in the template in app.component.ts

....
      <h2>My Collection</h2>
      <h3>has more than one book? {{ store.hasMorethanOneBook()}}</h3>

This does not work and shows error messages in the browser.

If possible, provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

Yes

Hi @DruidNx
This is not a bug:
Your function hasMorethanOneBook returns a Signal<boolean>, hence in the template you would need an additional incovation on the returned signal, like:

<h3>has more than one book? {{ store.hasMorethanOneBook()()}}</h3>

What you most probably wanted to do, was using a getter function for a simplified call syntax:

// books.store.ts
public get hasMorethanOneBook() {
    return computed(() => this.state().length > 1)
  }

You can read more here

Does this work for you?

Ah yes, makes sense. Works now!