// Will fail if plugins invalidate the tree
Will fail if plugins invalidate the tree
// Will fail if plugins invalidate the tree
func (p *Page) renderComponentWS(ctx context.Context, comp Componenter) {
	if p == nil {
		p.logger.Error().Str("id", comp.GetID()).Str("name", comp.GetName()).Msg("render component on dead page")
		return
	}
	oldTag := p.findComponentInTree(comp.GetID())
	if oldTag == nil {
		p.logger.Error().Str("id", comp.GetID()).Str("name", comp.GetName()).
			Msg("render component ws: can't find component in tree")
		return
	}
	newTreeNode, err := p.PipelineDiff.runNode(ctx, io.Discard, comp)
	if err != nil {
		p.logger.Error().Str("id", comp.GetID()).Str("name", comp.GetName()).
			Msg("render component ws: pipeline run node")
		return
	}
	var newTag *Tag
	newTags, ok := newTreeNode.(*NodeGroup)
	if ok && len(newTags.Get()) != 0 {
		newTag, ok = newTags.Get()[0].(*Tag)
	} else {
		newTag, ok = newTreeNode.(*Tag)
	}
	if !ok {
		p.logger.Error().Str("id", comp.GetID()).Str("name", comp.GetName()).
			Msg("render component ws: new node is not a tag, component, or group")
		return
	}
	diffs, err := p.Differ.Trees(comp.GetID(), "", oldTag, newTag)
	if err != nil {
		p.logger.Err(err).Str("id", comp.GetID()).Str("name", comp.GetName()).Msg("diff trees")
		return
	}
	if len(diffs) != 0 {
		p.wsSend(p.diffsToMsg(diffs))
		oldTag.name = newTag.name
		oldTag.void = newTag.void
		oldTag.attributes = newTag.attributes
		oldTag.nodes = newTag.nodes
	}
}
func ( p * Page ) renderComponentWS ( ctx context . Context , comp Componenter ) { if p == nil { p . logger . Error ( ) . Str ( " " , comp . GetID ( ) ) . Str ( " " , comp . GetName ( ) ) . Msg ( " " ) return } oldTag := p . findComponentInTree ( comp . GetID ( ) ) if oldTag == nil { p . logger . Error ( ) . Str ( " " , comp . GetID ( ) ) . Str ( " " , comp . GetName ( ) ) . Msg ( " " ) return } newTreeNode , err := p . PipelineDiff . runNode ( ctx , io . Discard , comp ) if err != nil { p . logger . Error ( ) . Str ( " " , comp . GetID ( ) ) . Str ( " " , comp . GetName ( ) ) . Msg ( " " ) return } var newTag * Tag newTags , ok := newTreeNode . ( * NodeGroup ) if ok && len ( newTags . Get ( ) ) != 0 { newTag , ok = newTags . Get ( ) [ 0 ] . ( * Tag ) } else { newTag , ok = newTreeNode . ( * Tag ) } if ! ok { p . logger . Error ( ) . Str ( " " , comp . GetID ( ) ) . Str ( " " , comp . GetName ( ) ) . Msg ( " " ) return } diffs , err := p . Differ . Trees ( comp . GetID ( ) , " " , oldTag , newTag ) if err != nil { p . logger . Err ( err ) . Str ( " " , comp . GetID ( ) ) . Str ( " " , comp . GetName ( ) ) . Msg ( " " ) return } if len ( diffs ) != 0 { p . wsSend ( p . diffsToMsg ( diffs ) ) oldTag . name = newTag . name oldTag . void = newTag . void oldTag . attributes = newTag . attributes oldTag . nodes = newTag . nodes } }
Will fail if plugins invalidate the tree
Will fail if plugins invalidate the tree
// TODO: replace discard