コード例 #1
0
func (filler *viewModelFiller) Section(node *viewmodel.SectionNode) {
	filler.object = js.Global.Get("Object").New()

	filler.object.Set("type", "section")
	filler.object.Set("label", node.Label())
	{
		availableFiller := newViewModelFiller()
		node.Available().Specialize(availableFiller)
		filler.object.Set("available", availableFiller.object)
	}

	observableNodes := ko.NewObservableArray()
	filler.object.Set("nodes", observableNodes)

	updateSubNodes := func() {
		nodes := node.Get()
		objNodes := make([]*js.Object, len(nodes))

		for index, subNode := range nodes {
			subFiller := newViewModelFiller()
			subNode.Specialize(subFiller)
			objNodes[index] = subFiller.object
		}
		observableNodes.Set(objNodes)
	}
	node.Subscribe(updateSubNodes)
	updateSubNodes()
}
コード例 #2
0
// NewSectionNodeTexter returns a new instance of SectionNodeTexter.
func NewSectionNodeTexter(node *viewmodel.SectionNode, listener ViewModelListener) *SectionNodeTexter {
	texter := &SectionNodeTexter{
		node:     node,
		listener: listener}

	texter.updateSubTexter()
	node.Subscribe(func() {
		texter.updateSubTexter()
		listener.OnMainDataChanged()
	})
	node.Available().Subscribe(func(bool) {
		listener.OnMainDataChanged()
	})

	return texter
}