git.fiddlerwoaroof.com
Browse code

feature: add saga channel example

Ed Langley authored on 06/10/2019 20:23:31
Showing 1 changed files
... ...
@@ -1,13 +1,35 @@
1
-import { takeLatest, take, put } from "redux-saga/effects";
1
+import {} from "@redux-saga/is";
2
+import { channel, buffers } from "redux-saga";
3
+import { takeEvery, fork, takeLatest, take, put } from "redux-saga/effects";
2 4
 import { updateIp } from "./reducer";
3 5
 
6
+function* channelWorker(thing) {
7
+  console.log("the thing is:", thing);
8
+  yield;
9
+}
10
+
11
+function* channelListener(channel) {
12
+  console.log("hi from the listener");
13
+  yield takeEvery(channel, channelWorker);
14
+}
15
+
4 16
 export function* rootSaga() {
17
+  const myChannel = channel(buffers.sliding(10));
18
+
19
+  console.log("hi");
20
+  yield fork(channelListener, myChannel);
21
+
22
+  myChannel.put("hi");
23
+
5 24
   yield put({ type: "co/fwoar/APP_INIT" });
25
+  myChannel.put({ a: 3 });
6 26
   yield takeLatest("GET_IP", ipWorker);
7 27
   while (true) {
8 28
     yield take("FAIL");
9 29
     throw new Error("FAILURE!");
10 30
   }
31
+
32
+  yield appReady;
11 33
 }
12 34
 
13 35
 export function getIp() {