This page is part of a static HTML representation of TriTarget.org at https://tritarget.org

Ember Query Params Cell pattern

Sukima9th May 2023 at 2:46pm

When it comes to Query Params it can be frustrating to have to prop drill from a controller to components especially with the data-down actions-up paradigm doubling the prop drilling.

This pattern makes this much better by pushing the properties into a Cell object.

import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';

class MyQueryParams {
  @tracked foo = '';
  @tracked bar = '';
}

export default class MyController extends Controller {
  params = new MyQueryParams();
  queryParams = [
    { 'params.foo': 'foo' },
    { 'params.bar': 'bar' },
  ];
}

Controller example

With this example we have the ability to pass this.params to any component and within the component they can set properties and everything just works.