aurelia / aurelia/store

Call the changedHandler after the value has been set

Open
#69 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

breaking-change enhancement
Dominant language
TypeScript
Stars
100
Forks
22
PR merge metrics
No merged PRs in 30d

Description

I'm submitting a feature request

  • Library Version:
    1.1.0

Please tell us about your environment:

  • Operating System:
    all

  • Node Version:
    all

  • NPM Version:
    all
  • JSPM OR Webpack AND Version
    both
  • Browser:
    all

  • Language:
    all

Current behavior:
Whenever we subscribe to a part of the state, the changed handler will be called before the actual state is changed.

@autoinject()
@connectTo({
  selector: {
    list: store => store.state.pipe(pluck('list'))
  }
})
export class App {
  store;
  list : string[] = [];
  normalBinding : string;

  constructor(store : Store<any>) {
    this.store = store;
    this.store.registerAction('addList', addList);
  }

  listChanged(newValue, oldValue) {
    // this.list does not have the newValue yet, in contrast with normal 
    // aurelia behavior where this.list would have the value when this handler is called
  }

   normalBindingChanged(newValue, oldValue){
     // this.normalBinding is already set at this moment
   }
  }
}
  • What is the expected behavior?
    The bound value should be set before the changed-handler is invoked

  • What is the motivation / use case for changing the behavior?
    It aligns better with the default Aurelia behavior and meets the expectations of users better

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @connectTo selector example and trace how the selected list value reaches listChanged. Add a regression test showing that the bound value is updated before its changed handler runs, then verify the existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.