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

feat: enable compatibility of xstate-vue with Vue 3 #1629

Merged
merged 13 commits into from
Dec 29, 2020

Conversation

sarahdayan
Copy link
Contributor

@sarahdayan sarahdayan commented Nov 12, 2020

This PR enables compatibility of xstate-vue with Vue 3. It removes the peer dependency with @vue/composition-api. This creates a breaking change.

I had trouble running tests on my machine, I'll see how things look like in the CI and will take action to rectify if necessary.

cc @Andarist if you want to take a look 🙂

closes #1252

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2020

🦋 Changeset detected

Latest commit: 42f4e20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@xstate/vue Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@davidkpiano
Copy link
Member

davidkpiano commented Nov 13, 2020

Thanks, Sarah! I think the way the tests were previously set up aren't playing well with the Vue 3 typings:

... is not assignable to parameter of type 'VueClass'

Summary of all failing tests
 FAIL  packages/xstate-vue/test/useMachine.test.ts
  ● Test suite failed to run

    packages/xstate-vue/test/useMachine.test.ts:49:47 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.
        Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' provides no match for the signature 'new (...args: any[]): Vue'.

    49     const { getByText, getByTestId } = render(UseMachine);
                                                     ~~~~~~~~~~
    packages/xstate-vue/test/useMachine.test.ts:59:47 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.

    59     const { getByText, getByTestId } = render(UseMachine, {
                                                     ~~~~~~~~~~
    packages/xstate-vue/test/useMachine.test.ts:71:47 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.

    71     const { getByText, getByTestId } = render(UseMachine, {
                                                     ~~~~~~~~~~
    packages/xstate-vue/test/useMachine.test.ts:81:27 - error TS2769: No overload matches this call.
      Overload 1 of 3, '(component: VueClass<Vue>, options?: ThisTypedMountOptions<Vue> | undefined): Wrapper<Vue>', gave the following error.
        Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
          Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.
      Overload 2 of 3, '(component: ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>, options?: ThisTypedMountOptions<...> | undefined): Wrapper<...>', gave the following error.
        Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
          Types of property 'computed' are incompatible.
            Type '{ <T>(getter: ComputedGetter<T>): ComputedRef<T>; <T>(options: WritableComputedOptions<T>): WritableComputedRef<T>; }' is not assignable to type 'Accessors<DefaultComputed>'.
              Index signature is missing in type '{ <T>(getter: ComputedGetter<T>): ComputedRef<T>; <T>(options: WritableComputedOptions<T>): WritableComputedRef<T>; }'.
      Overload 3 of 3, '(component: FunctionalComponentOptions<Record<string, any>, PropsDefinition<Record<string, any>>>, options?: MountOptions<Vue> | undefined): Wrapper<...>', gave the following error.
        Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'FunctionalComponentOptions<Record<string, any>, PropsDefinition<Record<string, any>>>'.
          Property 'functional' is missing in type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' but required in type 'FunctionalComponentOptions<Record<string, any>, PropsDefinition<Record<string, any>>>'.

    81     const wrapper = mount(UseMachine, { localVue });
                                 ~~~~~~~~~~

      node_modules/vue/types/options.d.ts:132:3
        132   functional: boolean;
              ~~~~~~~~~~
        'functional' is declared here.
    packages/xstate-vue/test/useMachine.test.ts:90:14 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.

    90       render(UseMachineNoExtraOptions);
                    ~~~~~~~~~~~~~~~~~~~~~~~~

 FAIL  packages/xstate-vue/test/useService.test.ts
  ● Test suite failed to run

    packages/xstate-vue/test/useService.test.ts:36:39 - error TS2345: Argument of type '{ components: { UseService: typeof UseService; }; template: string; props: string[]; }' is not assignable to parameter of type 'VueClass<Vue>'.
      Type '{ components: { UseService: typeof UseService; }; template: string; props: string[]; }' is not assignable to type 'new (...args: any[]) => Vue'.
        Type '{ components: { UseService: typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue"); }; template: string; props: string[]; }' provides no match for the signature 'new (...args: any[]): Vue'.

    36     const { getAllByTestId } = render(twoServices, {
                                             ~~~~~~~~~~~
    packages/xstate-vue/test/useService.test.ts:57:49 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.
        Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' provides no match for the signature 'new (...args: any[]): Vue'.

    57     const { getByTestId, updateProps } = render(UseService, {
                                                       ~~~~~~~~~~

 FAIL  packages/xstate-vue/test/useFSM.test.ts
  ● Test suite failed to run

    packages/xstate-vue/test/useFSM.test.ts:14:47 - error TS2345: Argument of type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to parameter of type 'VueClass<Vue>'.
      Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' is not assignable to type 'new (...args: any[]) => Vue'.
        Type 'typeof import("/Users/davidkpiano/Code/xstate-v4/packages/xstate-vue/node_modules/vue/dist/vue")' provides no match for the signature 'new (...args: any[]): Vue'.

    14     const { getByText, getByTestId } = render(UseFSM);
                                                     ~~~~~~

I can help look into these. Might just need some refactoring (instead of inlining the test components).

@pearofducks
Copy link
Contributor

pearofducks commented Nov 13, 2020

Just a heads up - this component isn't Vue 3 compatible at the moment.

Also I'm not sure if the 1.x version of @vue/test-utils is compatible with Vue 3 - there's a 2.x version on the next tag though!

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist
Copy link
Member

@sarahdayan could you merge master to your branch? It seems that CI was not running for external contributions - I've fixed that now.

@guilipan
Copy link

any progress here?

@davidkpiano
Copy link
Member

any progress here?

Patience 🙏

@TheDutchCoder
Copy link
Contributor

Any movement on this?
It's kind of a critical thing for us Vue devs :)

davidkpiano and others added 3 commits December 15, 2020 14:35
# Conflicts:
#	package.json
#	packages/xstate-vue/package.json
#	yarn.lock
package.json Show resolved Hide resolved
@Andarist Andarist merged commit 87d0acd into statelyai:master Dec 29, 2020
@github-actions github-actions bot mentioned this pull request Dec 29, 2020
dsngo added a commit to dsngo/xstate that referenced this pull request Feb 24, 2021
* Created xstate-svelte directory and added support for @xstate/fsm.

* Added support for xstate and tests.

* Updated svelte-jester to allow running tests from project root.

* Add createModel + test

* Update test to show full typing

* Rename withUpdaters -> withAssigners, fix mapValue types

* Fix typings for createModel

* Improve types

* Do not crash when stopping already stopped interpreter. Fixes statelyai#1697

* Add changeset

* WIP: model updates

* Simplify model

* Add comment

* Update resources.md

* Fixed an issue with `process` references not being removed correctly from the `@xstate/react` UMD bundles (statelyai#1756)

* 'rollup-replace' replaces process.env.NODE_ENV declarations.

* rollup-replace is a dependency.

* 'rollup-replace' replaces process.env.NODE_ENV declarations.

* Use the same version of rollup-plugin-replace across the repo

* tweak changeset

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Version Packages (statelyai#1760)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Rename context -> initialContext, use ExtractEvent

* Remove actions property

* Fix types

* Update description in svelte.md

Add import statement: import replace from "@rollup/plugin-replace"; to documentation

* Refactoring!

* WIP

* Fixed an issue with events received from callback actors not having the appropriate `_event.origin` set

* Version Packages

* Finish refactoring

* Export createDevTools

* Update packages/xstate-inspect/src/utils.ts

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Update packages/xstate-inspect/examples/server.ts

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Add global shim

* Fix rollup config

* Add null check

* Add changeset and update README.md

* Fixed an issue with some external packages not being bundled correctly into the `@xstate/react` UMD bundles (statelyai#1780)

* Version Packages (statelyai#1781)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Switch to Vue 3 compatibility that has builtin support for the composition API (statelyai#1629)

* build: set Vue 3 as dev and peer dependencies

* refactor: import dependencies from Vue package

* refactor: import test dependencies from Vue package

* refactor: replace Composition API global with Vue

* build: remove Composition API package

* docs: add changeset

* fix: apply suggestion from code review

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Fix tests etc.

* Re-enable husky git hooks

* Remove unnecessary dep & config stuff

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: David Khourshid <davidkpiano@gmail.com>

* Version Packages

* Update README.md

Add Vue 3 template

* Version Packages

* Update docs

* Fixed a typo parenthesis in the docs (statelyai#1798)

* Ensure that services are registered by inspect client. Fixes statelyai#1797

* Add changeset

* Version Packages

* Update yarn.lock

* Update README.md

* `machine.resolveState(state)` calls should resolve to the correct value of `.done` property now (statelyai#1816)

* Version Packages

* Update resources.md

* Update resources.md

* Create deno.md (statelyai#1830)

* Create deno.md

Just wanted to mention how to get XState working on Deno.  Not sure if 'recipes' is the best place, but not sure of anywhere better?

* Update docs/recipes/deno.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Update resources.md

* Update resources.md

* Update resources.md

* Remove RestrictedActions

* Add model.reset()

* Revert changed types

* Fix TransitionsConfigMap

* Fix types in tests

* Remove unused function

* Add changeset

* Revert types

* Version Packages

* Add useMachineObserver

* Add tests

* Update resources.md

* Update resources.md

* Updated dependency versions

* Improved `.matches(value)` inference for typestates containing union types as values

* Changed minimum @types/jest version to 24.0.23

* Fix a bound TTypestate not being able to satisfy the default value

* Copied yarn.lock from master and then ran yarn

* Update resources.md

* Fsm actions no longer merged.

* Added 'service' to returned object

* Update resources.md

* Update .changeset/clean-walls-breathe.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Rename useMachineObserver -> useInterpret

* Move useInterpret to file

* Fixed URL to a codesandbox demoing @xstate/inspect using vanilla JS  (statelyai#1878)

It was pointing to TS template.

* Documented using useMachine. Adapted xstate-react examples.

* Added 'Services' section to svelte readme.

* Corrections to svelte readme

* Corrected link in svelte readme

* Remove duplicated import from React in xstate-viz (statelyai#1897)

* Remove React double import

* Add changeset for removing react double import

* Revert "Add changeset for removing react double import"

This reverts commit 859845f.

* Update resources.md

* Update resources.md

* Update immer

* Remove xstate-dev

* Fix TS issues

* Fixing types

* Add changeset

* Update resources.md

* Add support for "internal" transitions

* Update shy-toes-worry.md

* Add changeset

* Update resources.md

* Version Packages

* Update .changeset/afraid-eggs-wonder.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Update packages/xstate-fsm/src/index.ts

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Refactor

* Version Packages

* docs: remove Spectrum.chat

& where Spectrum.chat is appropriate, remind that GH Discussions is for XState-specific questions

* Update README.md

* Update README.md

* + discussions link

* replace Gitter "chat" with Discord

* Add useSelector + tests

* Fix types

* Version Packages

* Add test

* Separate useReactEffectActions

* Don't use instanceof

* Add test for comparison function

* Update resources.md

* Add useIsomorphicLayoutEffect + consolidate options assignment

* Update README.md

* Fixed an issue with synchronous initial updates not updating useMachine

* Move implementations update to a layout effect to avoid stale closure problems for layout effects

* Update resources.md

* Update resources.md

* Fix selector subscription

* Don't update guards

* Separate observer subscription

* Update resources.md

* Adds final states to test plan description

* Adds changeset

* Version Packages

* Revert options changes

* Add changesets

* Update useSelector

* Memoize listener

* Update resources.md

* Update resources.md

* Update resources.md

* Update README.md

* Version Packages

* add typestate type to service returned from react/fsm useMachine

* Add changeset

* Fixed @xstate/react UMD build by redeclaring toObserver (statelyai#1950)

* Version Packages (statelyai#1949)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Update resources.md

* docs: add new resource

Github - XState with React and Angular in Nx Workspace

* Update docs

* Update @xstate/react README.md

* Fix README.md

* Update resources.md

Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
Co-authored-by: David Khourshid <davidkpiano@gmail.com>
Co-authored-by: Dimitar Danailov <dimityr.danailov@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: jonasholbech <jh@jonasholbech.dk>
Co-authored-by: Sarah Dayan <dayan.sarah@gmail.com>
Co-authored-by: decaylala <decaylala@users.noreply.github.com>
Co-authored-by: Tom Byrer <tomByrer@gmail.com>
Co-authored-by: Hosein <hosein2398@gmail.com>
Co-authored-by: Jim Wheaton <jimwheaton@gmail.com>
Co-authored-by: Luke Karrys <lukekarrys@gmail.com>
Co-authored-by: Chau Tran <nartc7789@gmail.com>
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.

@xstate/vue not working with vue beta
6 participants