Exemple #1
0
func (s *StdWeb) Publish(nodes []*core.Node) {
	s.m.Lock()
	defer s.m.Unlock()

	s.updateID++
	newData := NewUpdate(s.runID, s.updateID)

	rctx := core.NewRenderContext(s.runID, s.updateID)
	for _, node := range nodes {
		u := &NodeUpdate{
			ID:      node.ID(),
			Payload: node.Render(rctx),
		}
		newData.Nodes[node.ID()] = u
		// Keep track of all recent updates we've sent. This way, when a client
		// reconnects, it can get the last updates.
		s.recentNodeUpdates[node.ID()] = &timedNodeUpdate{
			updateID: s.updateID,
			update:   u,
		}
	}

	for ch := range s.listeners {
		select {
		case u := <-ch:
			newData.Merge(u)
		default:
		}
		ch <- newData
	}
}
Exemple #2
0
func (p *Publisher) Publish(nodes []*core.Node) {
	p.m.Lock()
	defer p.m.Unlock()

	rctx := core.NewRenderContext(StaticRunID, p.updateID)
	for _, n := range nodes {
		p.payloads[n.ID()] = n.Render(rctx)
	}
}
Exemple #3
0
func (s *StdWeb) baseHandler(w http.ResponseWriter, r *http.Request) {
	s.m.Lock()
	defer s.m.Unlock()
	rctx := core.NewRenderContext(s.runID, s.updateID)
	w.Write([]byte(s.tree.Slot().Node().Render(rctx)))
}
Exemple #4
0
func Render(n *core.Node) string {
	return n.Render(core.NewRenderContext(StaticRunID, StaticUpdateID))
}