Component Party - new chapter: context

Component party is still growing and getting new features (or better: examples) from the supported frameworks inclusing Aurelia.

The latest addition is “Context”. Is there an Aurelia alternative for this feature?
See: Component Party
More info: Content: add `Component Composition > Context` · Issue #42 · matschik/component-party · GitHub

1 Like

I think that you are looking for aurelia-store. You can find the documentations here: Managing App State | Aurelia.

From the other documentation it looks like they consider “context” to be something more light weight than using a store.

As you probably already know there is a bindingContext in Aurelia that has a scope and is somewhat similar. You can read about it here Binding: How it Works | Aurelia

Also see discussion here web - set binding context for custom element aurelia - Stack Overflow and How to bind to the current bindingContext · Issue #195 · aurelia/templating · GitHub

If you look in the vue example they use some form of data injection so you can define a class, set its properties in the parent and inject it to relevant childs by DI. See example below. Written in the editor here so probably full of typos. You might consider some kind of control over how the object is updated.

export class Theme
{
   public level:number = 0;
}

@inject(Theme)
export class MyParent
{
   constructor(theme: Theme) {
    this.theme= theme;
   this.theme.level = 3;
}
@inject(Theme)
export class MyGrandGrandChild
{
   constructor(theme: Theme) {
    this.theme= theme;
 }

and the html for the parent

<div><child><grand-child><my-grand-grand-child></my-grand-grand-child></grand-child></child>

and the html for the gran child

<template>
<div>${theme.level}</div>
</template>
3 Likes

I’d agree - I think this example is relates most closely with the inject/autoinject api in Aurelia where you have a shared service/class that gets injected and shared between components and deeply nested child components.

Thanks all, I will update the component party for aurelia based on your input.

3 Likes