question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing the controller / services

See original GitHub issue

Would it hurt, if we were able to access the corresponding Controller from the serialize and deserialize methods?

I am asking primarily because I need to synchronously access the store service, in order to lookup a record for an ID. Basically something like this:

new QueryParams({
  someModel: {
    defaultValue: null,

    serialize(model) {
      return model ? get(model, 'id') : '';
    },

    deserialize(id) {
      return id ? get(this, 'store').peekRecord('model-name', id) : null;
    }
});

Do you think this is a form of unhealthy entanglement, even though the lookup is guaranteed to work synchronously?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
evoactivitycommented, Jun 28, 2018

@roberkules I’m going to try an aproach today using a computed property which is the actual records array with the url parameters just being an array of ids, when that array updates the computed property should recompute a corresponding array.

@offirgolan @buschtoens would you say that sounds like a reasonable way to implement this functionality?

edit: turns out I didn’t need a computed property at all.

In the setup() hook I added

queryParams.chosenQualificationIds.forEach((id) => {
    let record = this.store.peekRecord('course', id);
    get(this, 'selectedQualifications').addObject(record);
});

Then I’m using an ember-power-select component to modify the array, instead of just doing onchange=(action (mut selectedQualifications)) I used an actions to modify both properties

actions: {
    setQualifications(records) {
      let ids = records.map((record) => record.id);
      set(this, 'chosenQualificationIds', ids);
      set(this, 'selectedQualifications', records);
    }
}

My query parameter maps to chosenQualificationIds

2reactions
potetocommented, Nov 22, 2017

I’ve had that thought before.

As @offirgolan says It’s definitely possible, although I would pass the controller in as an argument rather than have the context of those functions be rebound. I think having this in the serialize or derserialize functions be the controller would be slightly confusing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency injection into controllers in ASP.NET Core
Services are typically defined using interfaces. ... Accessing app or configuration settings from within a controller is a common pattern.
Read more >
Various ways of accessing DI services
Constructor injection is possibly the most common way of accessing the DI services inside a controller. As the name suggests, constructor ...
Read more >
Chapter 5. Understanding controllers and services - Griffon in ...
Simply put, controllers have the responsibility to react to inputs, usually coming from the UI.
Read more >
Accessing Service Layer from Controller in MVC Project
I'm now trying to relocate all business logic to a Services project that contains a bunch of classes. To start I added a...
Read more >
Configure the controller services | CDP Public Cloud
To add a Controller Service to your flow, right-click on the Canvas and select Configure from the pop-up menu. · Select the Controller...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found