Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vuex typescript recipe example #61

Merged
merged 2 commits into from
May 6, 2020
Merged

Add Vuex typescript recipe example #61

merged 2 commits into from
May 6, 2020

Conversation

euaaaio
Copy link
Member

@euaaaio euaaaio commented Apr 19, 2020

Resolve logux/vuex#7

Only this way you can use TS in Vuex 3 without decorators or other modules. Other ways are too specific. That's should be enough for today's documentation.

<details><summary>Vuex client</summary>

```ts
type State = number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s use a more real example of having object in the state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reduced code to be like Redux example 🤦🏻‍♀️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, I will update Redux example too. I did the same mistake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s wait for new Redux example to have the same store in the Vuex example

let store = new Logux.Store<State>({
state: 0,
mutations: {
increment (state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an example of mutation with parameters

}
})

store.commit.sync<IncrementMutation>({ type: 'increment' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need IncrementMutation template here?

Can we pass available actions to the Logux.Store to check types in commit.sync? It will dramatically reduce code size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for solution with @nikolay-govorov. We can use decorators or something like vuex-type-helper. I haven't tried that. It seems redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution I took from Vuex's issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is not a problem with the @logux/vuex binding, but with the Vuex itself. In Vuex v4, deeper support for TS is expected, and I believe it will be possible to type not only the state but also the signatures of actions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is fixed Redux example 2609816

I think passing IncrementMutation to store.commit.sync does not any useful. It will be better just recommend some good action creator library.

@euaaaio
Copy link
Member Author

euaaaio commented May 1, 2020

I made example like Redux and simplified it. We'll improve it in the near future, as discussed.

@euaaaio
Copy link
Member Author

euaaaio commented May 6, 2020

@ai, can be merged, I think.

@ai ai merged commit 51fa7ba into logux:master May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TS example to docs
3 participants