Skip to content

Commit f7ace71

Browse files
committed
fix: deprecate symbols as message names (#27)
1 parent 8e3da76 commit f7ace71

File tree

3 files changed

+5
-39
lines changed

3 files changed

+5
-39
lines changed

README.md

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This library brings the elmish pattern to react.
99
- [Basic Usage](#basic-usage)
1010
- [More about messages](#more-about-messages)
1111
- [Message parameters](#message-parameters)
12-
- [Symbols instead of strings](#symbols-instead-of-strings)
1312
- [Dispatch commands in the update map or update function](#dispatch-commands-in-the-update-map-or-update-function)
1413
- [Dispatch a message](#dispatch-a-message)
1514
- [Call an async function](#call-an-async-function)
@@ -240,44 +239,6 @@ In the **render** method you can add another button to increment the value by 10
240239
...
241240
```
242241
243-
### Symbols instead of strings
244-
245-
You can also use **Symbols** for the message type instead of strings:
246-
247-
1. Declare a Symbol for the message:
248-
249-
```ts
250-
const ResetMsg = Symbol("reset");
251-
```
252-
253-
1. Use this Symbol as message name:
254-
255-
```ts
256-
export type Message =
257-
...
258-
| { name: typeof ResetMsg }
259-
...
260-
```
261-
262-
1. Create the convenient function
263-
264-
```ts
265-
export const Msg = {
266-
...
267-
reset: (): Message => ({ name: ResetMsg }),
268-
...
269-
}
270-
```
271-
272-
1. Handle the new message in the `update` function:
273-
274-
```ts
275-
...
276-
case ResetMsg:
277-
return [{ value: 0 }];
278-
...
279-
```
280-
281242
## Dispatch commands in the update map or update function
282243
283244
In addition to modifying the model, you can dispatch new commands here.

installScript.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
// eslint-disable-next-line no-console
4+
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.");

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "atheck",
66
"license": "MIT",
77
"scripts": {
8+
"install": "node installScript.js",
89
"build": "npm run build:types && npm run build:js",
910
"build:types": "tsc --emitDeclarationOnly --project ./src",
1011
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --ignore \"./**/*.spec.ts\",\"./**/*.spec.tsx\" --source-maps inline",

0 commit comments

Comments
 (0)