Skip to content

Commit

Permalink
fix: deprecate symbols as message names (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
atheck committed Oct 14, 2022
1 parent 8e3da76 commit f7ace71
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
39 changes: 0 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ This library brings the elmish pattern to react.
- [Basic Usage](#basic-usage)
- [More about messages](#more-about-messages)
- [Message parameters](#message-parameters)
- [Symbols instead of strings](#symbols-instead-of-strings)
- [Dispatch commands in the update map or update function](#dispatch-commands-in-the-update-map-or-update-function)
- [Dispatch a message](#dispatch-a-message)
- [Call an async function](#call-an-async-function)
Expand Down Expand Up @@ -240,44 +239,6 @@ In the **render** method you can add another button to increment the value by 10
...
```
### Symbols instead of strings
You can also use **Symbols** for the message type instead of strings:
1. Declare a Symbol for the message:
```ts
const ResetMsg = Symbol("reset");
```
1. Use this Symbol as message name:
```ts
export type Message =
...
| { name: typeof ResetMsg }
...
```
1. Create the convenient function
```ts
export const Msg = {
...
reset: (): Message => ({ name: ResetMsg }),
...
}
```
1. Handle the new message in the `update` function:
```ts
...
case ResetMsg:
return [{ value: 0 }];
...
```
## Dispatch commands in the update map or update function
In addition to modifying the model, you can dispatch new commands here.
Expand Down
4 changes: 4 additions & 0 deletions installScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

// eslint-disable-next-line no-console
console.warn("react-elmish: Symbols for message names are deprecated now and will be removed in the next major version. Please convert all message names into strings.");
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "atheck",
"license": "MIT",
"scripts": {
"install": "node installScript.js",
"build": "npm run build:types && npm run build:js",
"build:types": "tsc --emitDeclarationOnly --project ./src",
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --ignore \"./**/*.spec.ts\",\"./**/*.spec.tsx\" --source-maps inline",
Expand Down

0 comments on commit f7ace71

Please sign in to comment.