mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
42 lines
960 B
TypeScript
42 lines
960 B
TypeScript
interface HelloChannel extends ActionCable.Channel {
|
|
hello(world: string, name?: string): void;
|
|
}
|
|
|
|
App = {};
|
|
App.cable = ActionCable.createConsumer();
|
|
const helloChannel = App.cable.subscriptions.create('NetworkChannel', {
|
|
connected(): void {
|
|
console.log('connected');
|
|
},
|
|
disconnected(): void {
|
|
console.log('disconnected');
|
|
},
|
|
received(obj: Object): void {
|
|
console.log(obj);
|
|
},
|
|
hello(world: string, name: string = 'John Doe'): void {
|
|
console.log(`Hello, ${world}! name[${name}]`);
|
|
}
|
|
}) as HelloChannel;
|
|
|
|
helloChannel.hello('World');
|
|
|
|
const channelParams: ActionCable.ChannelNameWithParams = {
|
|
channel: 'NetworkChannel',
|
|
token: 'foo',
|
|
data: {
|
|
bar: 'baz'
|
|
}
|
|
};
|
|
const channelWithParams = App.cable.subscriptions.create(channelParams, {
|
|
connected(): void {
|
|
console.log('connected');
|
|
},
|
|
disconnected(): void {
|
|
console.log('disconnected');
|
|
},
|
|
received(obj: Object): void {
|
|
console.log(obj);
|
|
}
|
|
});
|