Aurelia 2 State plugin action handler `action` parameter

Hi! I am using Aurelia 2 State plugin (ESNext).

I reproced an example from the docs:

// initial-state.js
export const initialState = {
  keywords: '',
};

// action-handlers.js
export function keywordsHandler(currentState, action) {
  console.log('action:', action);
  return action.type === 'newKeywords'
    ? { ...currentState, keywords: action.value }
    : currentState;
}

// main.js
import { StateDefaultConfiguration } from '@aurelia/state';
import Aurelia from 'aurelia';
import { keywordsHandler } from './action-handlers';
import { initialState } from './initial-state';
import { MyApp } from './my-app';

Aurelia.register(StateDefaultConfiguration.init(initialState, keywordsHandler))
  .app(MyApp)
  .start();

// my-app.html
<input
  value.state="keywords"
  input.dispatch="{ type: 'newKeywords', value: $event.target.value }"
/>

Well, whenever I type on the <input>, what I get on console is: “action: newKeywords”, meaning that I am getting action.type instead of action as the second argument to my action handler.

Is there a bug there, or what? Please help.

Thanks!

It’s recently changed here https://github.com/aurelia/aurelia/pull/1709

And will be out in beta-3. Our doc is ahead of our beta release. For now, it’ll be still (state, action, ...params). We will be doing a beta 3 release soon.

1 Like