developit / developit/unistore

incrementAsync action in the example does not work.

Open
#126 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.8k
Forks
134
PR merge metrics
No merged PRs in 30d

Description

```javascript
import "./style";
import { Component, render } from "preact";
import { Provider, createStore, connect } from "unistore";

let store = createStore({ count: 0 });

// If actions is a function, it gets passed the store:
let actions = store => ({
// Actions can just return a state update:
increment(state) {
return { count: state.count + 1 };
},

// The above example as an Arrow Function:
increment2: ({ count }) => ({ count: count + 1 }),

// Async actions are actions that call store.setState():
incrementAsync(state) {
setTimeout(() => {
store.setState({ count: state.count + 1 });
}, 100);
}
});

const App = connect("count", actions)(({ count, incrementAsync }) => (


Count: {count}


Increment

));

render(


,
document.body
);
```

I tried the use it in the example given like above, just changed the increment to incrementAsync but it doesnt update the state.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied JavaScript example and tracing how the connected incrementAsync action is invoked. Compare its behavior with the working increment action; the issue is done when clicking the button updates the displayed count.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
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.