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

Total rewrite in TypeScript #204

Merged
merged 1 commit into from
Mar 31, 2021
Merged

Total rewrite in TypeScript #204

merged 1 commit into from
Mar 31, 2021

Conversation

kevguy
Copy link
Collaborator

@kevguy kevguy commented Feb 22, 2021

This is a total rewrite of the whole library in TypeScript, and the changes are almost completely compatible with the original version.

  1. The lib is compiled with rollup instead of webpack with three formats: umd, cjs and es.
  2. Most of the objects in the library created using function prototypes are now using class.
  3. The example code (including bin/example.js and the example state machines in the examples folder) was modified accordingly and all work.
  4. You can do condition transition with an async function now (addressing this issue).
  5. All the tests are rewritten in TypeScript and stored in the test folder using jest instead of ava, due to ava requiring changes that conflicts with rollup (look at this ava issue) in order to support TypeScript.
  6. The original tests are in the test-js folder with minimal changes which will be covered later. All test cases passed except one.
  7. You cannot create a machine using const machine = StateMachine() anymore without the new keyword. One of the test cases was covering this, which is the case that didn't pass.
  8. When you run the factory method to create the machine and you have an base class constructor, you don't need to explicitly run this._fsm() in it anymore.
  9. When you use the apply method to extend your object to a state machine, you will get a new object instead of mutating the original object, that is running StateMachine.apply(obj) and use obj as it is, you have to do const newObj = StateMachine.apply(obj) and use newObj instead.

All in all, changes are mostly compatible with a few enhancements, and with type support .

@kungfooman
Copy link

I would rather have ES6 with import and export without the need of annoying bundlers (rollup). JSDoc will do the type checking.

@james-relyea
Copy link

This is great. @jakesgordon would you be willing to add new community members as maintainers for this library to keep it updated?

@kevguy kevguy changed the base branch from master to 4.0.0-beta March 31, 2021 11:06
@kevguy kevguy merged commit 73f3deb into jakesgordon:4.0.0-beta Mar 31, 2021
@nanchengjiumeng
Copy link

how can i install 4.0.0-beta use yarn.

@lantica
Copy link

lantica commented Nov 18, 2021

It's cool for the async support. May I ask is there any install guide for this branch?
I've tried using the build script rollup -c but it cannot build. @kevguy
The error message is as below:

$ /Users/admin/javascript-state-machine/node_modules/.bin/rollup -c

src/app/index.ts → dist/umd/index.js...
[!] (plugin rpt2) Error: /Users/admin/javascript-state-machine/src/jsm.ts(291,44): semantic error TS2343: This syntax requires an imported helper named '__spreadArray' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.
src/jsm.ts
Error: /Users/admin/javascript-state-machine/src/jsm.ts(291,44): semantic error TS2343: This syntax requires an imported helper named '__spreadArray' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.
    at error (/Users/admin/javascript-state-machine/node_modules/rollup/dist/shared/rollup.js:158:30)
    at throwPluginError (/Users/admin/javascript-state-machine/node_modules/rollup/dist/shared/rollup.js:21784:12)
    at Object.error (/Users/admin/javascript-state-machine/node_modules/rollup/dist/shared/rollup.js:22488:20)
    at Object.error (/Users/admin/javascript-state-machine/node_modules/rollup/dist/shared/rollup.js:21960:38)
    at RollupContext.error (/Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/src/rollupcontext.ts:37:18)
    at /Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/src/print-diagnostics.ts:41:11
    at arrayEach (/Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:516:11)
    at Function._.each [as forEach] (/Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9368:14)
    at printDiagnostics (/Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/src/print-diagnostics.ts:9:2)
    at Object.transform (/Users/admin/javascript-state-machine/node_modules/rollup-plugin-typescript2/src/index.ts:244:5)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

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.

5 participants