coco icon indicating copy to clipboard operation
coco copied to clipboard

Add Global Store Pattern

Open mrmiguu opened this issue 6 years ago • 3 comments

Allow users to embed a global store in their components, having them diff/recompile on mutation. This should be sprinkled intermittently throughout a component hierarchy and patch as needed.

mrmiguu avatar Mar 12 '19 06:03 mrmiguu

The pattern would look something like this:

func main() {
	coco.Globals(NewGlobals())
	coco.Render(NewApp())
}

and

type Up struct {
	Globals
}

func (u Up) OnUpClick() {
	u.Cocos = append(u.Cocos, "🥥")
	coco.Set(u)
}

mrmiguu avatar Mar 12 '19 06:03 mrmiguu

image

mrmiguu avatar Mar 15 '19 22:03 mrmiguu

Currently patching adds new listeners on the new component instance/copy. So when they're fired again, they're using the most up-to-date instance (e.g. coco.Set(...)).

To cause updating of globals to refresh other components embedding them, this would require new listeners to be assigned for all components using those globals; component instances embedding globals can only use the new context (w/ the new global) for the listeners if they're reassigned.

mrmiguu avatar Mar 17 '19 00:03 mrmiguu