Triggering a function when a bound property changes in Aurelia

I'm currently working with a viewmodel that seems to be functioning correctly.

@connectTo<State>({
  selector: (store) => store.state.pipe(pluck('domain')).pipe(pluck('games')),
  target: 'games',
})
@connectTo<State>({
  selector: (store) => store.state.pipe(pluck('domain')).pipe(pluck('myGames')),
  target: 'myGames',
})
@autoinject()
@customElement('games')
export default class Games {
  private static readonly ADD_TO_MYGAMES = 'addToMyGames';
  @bindable() games: Game[] = [];
  myGames: Game[] = [];

  constructor(
    private readonly store: Store<State>,
  ) {
    store.registerAction(Games.ADD_TO_MYGAMES, myGamesState);
  }

  available(game: Game): boolean {
    console.log("available", game);
    return !!this.myGames.find((i) => _.isEqual(i, game));
  }

  addGame(game: Game) {
    this.store.dispatch(Games.ADD_TO_MYGAMES, game);
  }
}

const myGamesState = async (current: State, game: Game) => {
  console.log(game);
  return produce(current, state => {
    state.domain.myGames.push(game);
  });
}

The issue arises when a new game is added to `myGames` as the view fails to refresh the `available` status.

<template bindable="games">
  <div class="columns">
    <ul class="column">
      <li repeat.for="game of games" class="level">
        <button class="button level-item is-fullwidth ${available(game) ? 'is-success' : ''}" click.delegate="addGame(game)"
          disabled.bind="available(game)">
          ${game.name}
        </button>
      </li>
    </ul>
  </div>
</template>

Any suggestions on how to resolve this problem?

Answer №1

It appears that you are utilizing a function reference. The correct usage would be:
disabled.call="available(game)"

For more information, please refer to: Aurelia's guide on function references

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the disable feature for React buttons not functioning properly when incorporating Tailwind CSS?

import React, { useState } from "react"; import facebook from "../UI/icons/facebook.png"; import Button from "../UI/Button/Button"; import Card from "../UI/Card/Card"; import twitter f ...

What is the recommended sequence for using decorators in NestJS: @Body(), @Params(), @Req(), @Res()?

How can I properly access the res object to send httpOnly cookies and validate the body with DTO? I keep running into issues every time I attempt it. What is the correct order for these parameters? ...

Dealing with Node.js, MongoDB, ISODate, and the complexities of managing time zones

Hey there, currently I am working with node js + mongodb. One issue I am facing is that whenever I insert data into a collection, it gets stored in the default ISODate format e.g. ISODate("2016-06-17T13:00:21.665Z") I want to make sure that the date fiel ...

Mapping TypeScript function return types based on parameter conditions using dictionaries

I'm trying to create a function in Typescript that will return different objects depending on the function parameter. Can someone help me find a solution? This is what I have so far: type outputMap = { 'x': number, 'y': st ...

Designate categories by utilizing the x-amz-tagging request header

I'm in the process of creating a Node program to upload files to aws s3, and I'm having trouble figuring out how to specify the x-amz-tagging with the request header. I attempted a solution, but it's not working as expected! function crea ...

Using TypeScript: Incorporating a map function in type declarations

My current situation involves the following types: type Value = boolean | number | string class Struct<T extends Value[] = Value[]> { constructor(fmt: string) { } pack(...args: T): Buffer { } } I am seeking guidance on how to replace &l ...

Nested promises utilized within functional programming techniques

Working on an Angular project involves developing a booking system with various scenarios. The challenge lies in handling different server calls based on the response of a promise, leading to a nested callback structure that contradicts the purpose of prom ...

XState TypeScript - utilizing the Interprete Service

I have developed a login system using a combination of TypeScript, xState, and React for the UI. The machine I have created includes the following configuration: import { LoginResponse } from 'async/authentication/responseModel'; import Data fro ...

Issue with Material Sort functionality when null objects are present

I've encountered an issue with my code. I created a feature that adds empty rows if there are less than 5 rows, but now the sort function is no longer functioning properly. Strangely, when I remove the for loop responsible for adding empty rows, the s ...

I am currently working with an input element that is set to hidden. I am trying to change its type to text using JavaScript, but I can't seem to figure out how to do it or if it is even possible

I'm stuck trying to change the type of an input element from hidden to text using JavaScript. I can't seem to figure out if it's even possible. Can someone please help me with this? Thanks! ...

Provide a unique <li> attribute for the JavaScript function to utilize

Is there a way to pass specific attributes from dropdown options to a javascript function? I have tried using .data() and .attr(), but the console keeps showing "undefined". Any suggestions on how to achieve this in a cleaner and simpler way would be gre ...

Execute a function using a click event within a statement

Is it possible to trigger a function with parameters based on the result of a statement? For example, can we achieve something like this: (click)="datavalue.elementDataCollection.length > 1 ? AddNewDialog (datavalue,datavalue.COCLabel,mainindex,i) : r ...

Using Node.js to write data to a JSON file

Currently, I am working on a program that scans through an array containing numerous links. It reads through each link, extracts specific text, and then stores it in an output file as JSON. However, I am facing an issue with formatting the JSON file. The ...

Removing an object in Three.js using scene.getObjectByName() method

When developing my game, I encountered a challenge. I'm loading 4 different buildings and creating 15 clones of each within a for loop. These clones are then added to an array called masterBuildingArray, which I iterate through using a forEach loop. T ...

Modifying Bootstrap Alert Styles with Jquery

I have an alert in my HTML form as shown below: <div class="alert bg-danger text-white alert-dismissible" id="alert" > <button type="button" class="close" data-dismiss="alert"><span>& ...

Confirming the Checkbox Field - ASP.NET with the Power of jQuery

I am currently working on a straightforward validation process for checking agreements using an asp:checkbox and an asp:button click. When the button is clicked, I have this function being called: OnClientClick="ValidateConditions();" The function itsel ...

Ways to conceal a button according to a particular trigger

On the page labeled standing-orders-details, I have configured it so that the display of the New Order button is hidden, but only if I first visit the new-order page. To begin, I need to ensure that the New Order button remains hidden on the standing-or ...

Creating an Angular Confirm feature using the craftpip library

Trying to utilize the angular-confirm library, but finding its documentation unclear. Implementing it as shown below: Library - In button click (login.component.ts), ButtonOnClickHandler() { angular.module('myApp', ['cp.ngConfirm']) ...

The javascript code appears to be functioning properly on desktop browsers but is not functioning as expected on Chrome's mobile browser

On my WordPress site, I have created a Java Bootstrap loan calculator that works perfectly on desktop. However, when I use Chrome on mobile, it is not functioning properly. I tried using the wp-coder plugin and also manually added the necessary code. Int ...

The Console.log() function displays the current state and value of a promise object within the Q library

Whenever I attempt to print a promise object from Q, the result that I receive is as follows: var Q = require('q'); var defaultPromise = new Q(); console.log('defaultPromise', defaultPromise); defaultPromise { state: 'fulfilled& ...