Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4836

didUpdateAttrs in glimmer-components or how to implement an asynchronous getter

$
0
0

@boesi wrote:

Hi

I try to get used to octane and so far I’m quite impressed. But I’m facing a problem where I even don’t know if I’m searching in the right direction - so maybe the topic is misleading.

I have a property I need to get from store depending on two arguments. If the property isn’t found I need to create a new one.

Up to now I have this code:

import Component from '@glimmer/component';

export default class MyClass extends Component {
	@inject store;
	@tracked property;

	async getOrCreateProperty() {
		let p = null;
		try {
			p = await this.store.findRecord('property-model, ...);
		} catch {
			p = this.store.createRecord('property-model', {
				argument1: this.args.argument1,
				argument2: this.args.argument2
			});
		}
		this.property = p;
		return p;
	}

	constructor(owner, args) {
		super(owner, args);
		this.getOrCreatePropertyUser();
	}
}

This works so far. But what should I do, if the two arguments change? With the classic components I could just implement didUpdateAttrs. But combining async and get doesn’t work and returning a promise in a getter doesn’t work either.

Or do I need a completely different approach?

Thanks for your help.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4836

Trending Articles