Published
Edited
Feb 24, 2020
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
require('https://cdn.rawgit.com/phoenixframework/phoenix/master/assets/js/phoenix.js')
Insert cell
Insert cell
require('phoenix-channels')
Insert cell
Insert cell
pc = require('phoenix@1.4.6')
Insert cell
Insert cell
socket = {
const socket = new pc.Socket(url);
socket.connect();
return socket;
}
Insert cell
Insert cell
Insert cell
Insert cell
value = Generators.observe(notify => {
let i = 0
let s = setInterval(() => notify(i++ % 100), 2000)
return () => clearInterval(s)
})
Insert cell
Insert cell
Insert cell
market_summaries = Generators.observe(notify => {
let state = {};
const channel = socket.channel('/subscription:market_summaries;86400')
channel.join()
.receive('ok', () => {
// 채널을 처음 구독하면 전체 데이터를 받습니다.
channel
.push('request', {timestamp: new Date() * 1000})
.receive('ok', ({data: [d]}) => {
state = createState(state, d.data)
notify(state)
})
})
.receive('error', () => console.log('join error'))
// 전체 데이터를 내려준 이후에는 업데이트된 항목만 받습니다.
channel.on('notification', ({data: [d]}) => {
state = createState(state, d.data)
notify(state)
})
return () => channel.leave()
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more