This repository has been archived on 2020-10-16. You can view files and clone it, but cannot push or open issues or pull requests.
counter/frontend/client/counter.js

21 lines
600 B
JavaScript
Raw Normal View History

import createChannel from "client/cable";
let callback; // declaring a variable that will hold a function later
const chat2 = createChannel("CountChannel", {
received({ message }) {
if (callback) callback.call(null, message);
},
});
const sendIncrement = (message) => chat2.perform("increment", { message });
const sendDecrement = (message) => chat2.perform("decrement", { message });
// Getting a message: this callback will be invoked once we receive
// something over ChatChannel
const setCallback = (fn) => {
callback = fn;
};
export { sendIncrement, sendDecrement, setCallback };