Quantcast
Channel: Ember.JS - Latest topics
Viewing all 4749 articles
Browse latest View live

hasDirtyAttributes do not work with nested attributes (JSON API)

$
0
0

@Nacho_B wrote:

Hi

I have a model returning from the backend using JSON API.

// models/client.js
import DS from 'ember-data';
export default DS.Model.extend({
    name: DS.attr(),
    full_name: DS.attr(),
    contacts: DS.attr(),
});

One of the attributes is an array of properties, “contacts”, coming from a jsonb column in the clients table in PostgreSQL. Not from a related table.

{
  "data": {
    "id": "230bc966-b109-4dc8-b99d-7ac29bbbb883",
    "type": "parties",
    "attributes": {
      "name": "Gran tienda",
      "full-name": "Gran tienda del universo",
      "contacts": {
        "included": [{
          "id": 1,
          "type": "contacts",
          "attributes": {
            "name": "pepe",
            "phone": "91 000 00 00"
          }
        }, {
          "id": 2,
          "type": "contacts",
          "attributes": {
            "name": "juan",
            "phone": "91 000 00 11"
          }
        }, {
          "id": 3,
          "type": "contacts",
          "attributes": {
            "name": "fernando",
            "phone": "91 000 00 22"
          }
        }]
      }
    }
  }
}

I have no problem to show, edit and save the Contacts elements, but it seems that “hasDirtyAttributes” do not detect changes in the nested Contacts.

I’ve read some things about similar problems, but the problems and the solution tricks are related to the REST API, not the JSON API. It is supposed that JSON API “understand” structures like mine, so no tricks should be necessary, isn’t it?

My intuition tells me that I must create a contacts model, like in a relationship:

// models/contact
import DS from 'ember-data';
export default DS.Model.extend({
    name: DS.attr(),
    phone: DS.attr()
});

And find a way to relate it to the client model.

export default DS.Model.extend({
    name: DS.attr(),
    full_name: DS.attr(),
    contacts: DS.hasMany('contact')
});

But there is not a true relationship between tables or entities, so I am really lost at this point.

I have also inserted “included”: [{ … }] as the property of the array, and the “id” and “type” attributes to maintain the JSON API data structure.

Can someone point me n the right direction to find the missing pieces?

Than you in advance:

Nacho B.

Posts: 1

Participants: 1

Read full topic


On running ember s I am getting the error of missing dependency for fsevents

$
0
0

@abhishek wrote:

On running ember s I am getting the error of missing dependency for fsevents. I am running my code on windows still I am getting this error. If I remove it from the package-lock.json and the npm shrinkwrap.json then I am getting error as “ReferenceError: regeneratorRuntime is not defined”

Posts: 1

Participants: 1

Read full topic

Newbie with questions

$
0
0

@NeveroddoreveN wrote:

Hey everyone! I just started playing Ember and I love it! The game is really great. Being the newbie that I am, I have some questions for more experienced players…

  1. Is there a button the keyboard that highlights all items in any given area?
  2. In the first dungeon, I acquired a bunch of jewels (ruby, amber, etc). Should I sell them or save them for later?
  3. Do enemies respawn in Ember?
  4. How do I use special skills? I heard that eventully my character will acquire special skills, but I don’t know how to use them.
  5. How does the experience boost work after using the bedroll?

And is there any other useful advice anyone could give me about this game, strategies to use, suggestions for gamplay, etc.? Any help is appreciated! Thanks so much!

Posts: 1

Participants: 1

Read full topic

Https://dancesweb.com/casino/ - 카지노사이트

Get Render Performance details via javascript hook

$
0
0

@gokulk138 wrote:

The render performance tab of the e-inspector looks cool and will definitely be useful for debugging performance lags. Is there a way I can get those data via a javascript hook in my application in dev mode. So, that I can use it for alerts and insights to developers.

Posts: 1

Participants: 1

Read full topic

Handlebars helper to break text strings into paragraphs at `\n` in a JSON file?

$
0
0

@jameshahn2 wrote:

Y’all got any more of them handlebars helpers?

Maybe one that can break strings into paragraphs at \n in a JSON file?

handlebars

Posts: 1

Participants: 1

Read full topic

Dynamic computes

$
0
0

@ahopkins wrote:

Is there such as thing as dynamic computed properties? I think a bit of code would make more sense.

Let’s say there is an object like this:

const fruitVendor = {
    weeks: {
        '2018-10-07': {
            available: ['apples', 'bananas', 'pears']
        },
        ...
    },
    ...
}

The data will always be in this format: fruitVendor.weeks.<YYYY-MM-DD>.available.

There could be a lot weeks, but I may only care about a computed property on this week. Right now I need to do something like this:

myComputedProperty: computed('fruitVendor.weeks', ...)

Whereas, ideally, I had something like this:

myComputedProperty: computed('fruitVendor.weeks.<getThisWeek()>.available', ...)

How do you handle something like this?

Posts: 3

Participants: 2

Read full topic

Define function/callbacks in ENV?

$
0
0

@Myrdhin wrote:

hello :slight_smile:

Could somebody help me to understand why I can not define a function/callback in config/environment.js ENV object?

I see functions/callbacks are removed when we build the application but I can not find where in the ember-cli source code.

Why I want functions/callbacks in ENV ? I use “ember-cli-sentry” addon and we can define some raven-js options in ENV.sentry.ravenOptions. I need one Raven option which is a callback shouldSendCallback (cf https://docs.sentry.io/clients/javascript/config/)

Thanks :smiley:

Posts: 1

Participants: 1

Read full topic


How to fetch associated model data from back-end only when required

$
0
0

@sundar wrote:

store.findRecord('school', school_id, {
          include: [
            'students',
             'students.records'
          ].join(',')

Using the above code fetching school, students, students’ records data in inital load. In the initial load, I don’t need students.records (only listing students initially)

Need student records only when clicking some button (Student Performance) Is there any way to fetch associated records separately and link with the existing model

I have sperate api endpoint for fetch students’ records

Posts: 1

Participants: 1

Read full topic

Route only in DEV mode?

$
0
0

@Myrdhin wrote:

Hello,

Somebody know how to define a route (in the router) only in DEV mode. I would like files (controller, route, template) associated with this route are not compiled in the PROD build too.

Thanks for your help

Posts: 1

Participants: 1

Read full topic

ES6 replacement for Ember.testing

$
0
0

@Hummingbird wrote:

When adding ember-simple-auth to a project, I noticed that Ember.testing is being used, for instance here

I was wondering if there is an ES6 replacement, as importing Ember from 'ember' will probably cause issues with three shaking in the future?

I noticed that using Ember.testing without an import seems to work fine, however I am not quite sure if this is something that should be done at all…

Posts: 1

Participants: 1

Read full topic

How to wait for a transaction to be finished

$
0
0

@belgoros wrote:

I’m stick with a weird transaction racing when using ESA. I identify a User as follows in current-user service:

loadCurrentUser() {
    this.get('flashMessages').clearMessages();
    if (this.get('session.isAuthenticated')) {
      return this.get('store').queryRecord('user', { me: true }).then((user) => {
        this.get('flashMessages').success(this.get('i18n').t('flash.signed_in'));
        this.get('currentShop').setShop(user.get('shop'));
        this.set('user', user);
      });
    } else {
      this.get('flashMessages').info(this.get('i18n').t('flash.signed_off'));
      return RSVP.resolve();
    }
  }

In application route:

export default Route.extend(ApplicationRouteMixin, {
  currentUser: service('current-user'),

  beforeModel() {
    return this._loadCurrentUser();
  },

  sessionAuthenticated() {
    this._super(...arguments);
    this._loadCurrentUser();
  },

  _loadCurrentUser() {
    return this.get('currentUser').loadCurrentUser().catch(() => this.get('session').invalidate());
  }
});

After authentication I redirect to dashboard route:

#environment.js

ENV['ember-simple-auth'] = {
    routeAfterAuthentication: 'dashboard'
  };

In dashboard route I load shops:

export default Route.extend(AuthenticatedRouteMixin, {
  currentUser: service('current-user'),
  currentShop: service('current-shop'),

  model() {
    return this.store.findAll('shop');
  }
});

What is happening is that I have two end-point hit, both requiring a User to be found or created in the backend based on the data encoded in the token passed in from Ember. How is possible to wait the end of users/me authentication end-point to finish before hitting the dashboard route ? Thank you.

Posts: 1

Participants: 1

Read full topic

Ember action on component not rendering what is inside conditional

$
0
0

@yefan15 wrote:

I am an Ember beginner and am not too sure why my code is not working. I have a component that has a button that I have assigned an action to. The action is to set a value to true so that conditional I defined on my template can show some some html elements. I know that the code is setting the value correctly it is just not rendering the HTML on my template.

Example: Button icon: <span id=“search”>

<input type=“submit” value="" aria-label=“search” alt=“perform search” {{action “enterResults”}}>

</span>

{{#if isNoResults}}

<div class=“pac-container pac-logo rectangle”>

<div class=“pac-item”>

<span class=“pac-icon pac-icon-marker hide-pac-icon”></span>

<span class= “pac-item-query”>

<span class= “pac-matched”>

<p class=“dynamic”> “{{address}}”</p>

</span>

</span>

</div>

</div>

{{/if}}

{{#if isNoResults}}

Action:

enterResults() { if (this.get(‘someElemenet’) === this.get(‘anotherElemment’)) {

    doSomething();

  } else{
  • it reaches the block but nothing shows this.set(‘isNoResults’, true);

    } 
    

}

Posts: 1

Participants: 1

Read full topic

Component manager thoughts?

$
0
0

@ryanto wrote:

I spent some time today playing with the new component managers that landed in 3.4. I’ve got to say, it’s been a lot of fun :smiley:

I created a few silly managers, nothing production ready. Maybe the most useful manager I came up with was a singleton manager. It always returned the same component instance, no matter how many times it was rendered.

I know from the RFC that these managers unlock template only components, which is pretty cool.

Outside of that, the use cases for these managers seem a little vague to me, so I figured I’d start a thread asking about it!

I’m wondering what sort of managers the core team and Ember developers hope to see with this new API. Are there any other creative ideas that managers unlock?

Posts: 1

Participants: 1

Read full topic

How to deal with i18n in integration tests?

$
0
0

@Bauke wrote:

Let’s say I have a component that displays the next localized text:

Your score is 6

Using ember-i18n and ember-test-selectors it looks like this:

<div data-test-score>
  {{i18n 'yourScoreIs' score=6}}
</div>

In the integration test I’d like to make sure the score is displayed correctly, but of the different assertions I can make none of them feels right.

assert.dom('[data-test-score]').hasText('Your score is 6');
// Breaks as soon as the translation changes.
// Also depends heavily on the chosen language.

assert.dom('[data-test-score]').includesText('6');
// Assumes the given value is not part if the translation.
// For example, breaks if translation is changed to "Out of 6 attempts, your best score is...".

assert.dom('[data-test-score]').hasAnyText();
// Doesn't really test if the score is displayed.

One solution could be to mock the i18n service to always return the same value.

const i18n = Service.extend({
  t(key, data = {}) {
    let output = 'tStub ' +  Object.entries(data)
      .map(entry => `${entry[0]}=${entry[1]}`)
      .join(' ');

    return output.trim(); 
  }
});

this.inject.service('i18n', { as: 'i18n' });

Then an assertion can be made to simply check if some translation is displayed and the right value is passed in.

assert.dom('[data-test-score]').hasText('tStub score=6');

What do you think of this solution? Do you might have an alternative strategy?

Posts: 1

Participants: 1

Read full topic


Ad-hoc custom computed property macro

$
0
0

@ondrejsevcik wrote:

Is it possible to create custom computed property macro for specific use case?

Example:

I have an ember object with properties that share most of the logic. This logic is extracted into it’s own method. What I don’t like is that I have to repeat dependent keys, because it’s easy to misspell.

// ember object
....
secondValues: computed('values.@each.time', function() {
    let steps = 60 * 1000;
    return this.getValues(steps, start, end);
}),

hourValues: computed('values.@each.time', function() {
    let steps = 60 * 60 * 1000;
    return this.getValues(steps, start, end);
}),
//... and so on

It would be nice if I could turn that method into custom computed macro that would be specific for this model. The macro would know what properties it depends on so I could omit the dependent keys when declaring properties.

// computedTimeValues is custom macro

secondValues: computedTimeValues(60 * 1000),
hourValues: computedTimeValues(60 * 60 * 1000),

Is something like this possible? Or is it in general bad idea? I’ve never created custom macro so I’m not sure how to do that.

Thanks

Posts: 1

Participants: 1

Read full topic

Yield multiple dynamic params

$
0
0

@CezaryH wrote:

Hey, I wonder if there’s a way to yield multiple dynamic params from component.

I imagine that would work like that:

{
  arrayData: [1,2]
}

{{#test-component data=arrayData as |one two|}}
  {{one}} //prints one
  {{two}} //prints two
{{/test-component}}

Any ideas how to achieve something like that?

Posts: 1

Participants: 1

Read full topic

DHTML &"The Ember Way"

$
0
0

@melriffe wrote:

I’m on a project where there’s a requirement to display N number of drop-downs, but 1 at a time. For example: when first entering the edit page a drop-down is displayed. after a selection has been made, a brand new drop-down is displayed before the first one. and so on until the maximum number has been reached.

Because I’ve been writing software for a while (just not front-ends) I immediately thought DHTML (yes I know it’s not a separate tech but the amalgamation of HTML, CSS, and JS). I haven’t written any (good) DHTML since jQuery 1.x. :wink: So, I’m trying to dust off, and update my DHTML skills.

But then I have this question: how would Ember do this? does Ember already support the idea of DHTML? If so, how?

Thanks, in advance, for any guidance received.

Posts: 1

Participants: 1

Read full topic

Get data from route as JSON for jQuery/fullcalendar

$
0
0

@brx wrote:

How do I get JSON from store for jQuery/fullcalender?

component template:

{{yield}}

component JS:

export default Component.extend({
  didInsertElement() {
    $('.jquerycal').fullCalendar({
      events: this.get('events')
  },
  willDestroyElement() {
    $('.jquerycal').fullCalendar().destroy();
  }
});

first approach was hardcoding some array with data, which works:

export default Route.extend({
  model() {
    return [{
      type: 'events',
      id: '96',
      title: 'All Day Event',
      start: '2018-10-01',
      color: '#783f53'
    },...]
  }
});

then tried another route, which works as well (with plain json returned):

export default Route.extend({
  model() {
   return new RSVP.Promise(function(resolve) {
     later(function() {
       let data = Ember.$.getJSON('http://someurl.com/data?start=2018-08-27&end=2018-10-08');
       resolve(data);
      }, 400);
   });
  }
});

but now, with the following route, I got stuck. I use mirage to get the data.

export default Route.extend({
  model() {
    return this.store.findAll('event');
  }
});

In the console I see mirage returning succesfully data. When I do the following in the component JS…

console.log(this.get('events'));

… I’ll get an object.

I tried some things like…

let dataArr = this.get('events');
dataArr.map(item => {
    console.log(item.get('title'));
});

… which returns all titles, but fullcalender expects the complete JSON of all events.

I’m sure I’m overlooking something, but I don’t get it.

Posts: 3

Participants: 3

Read full topic

jQuery component

$
0
0

@brx wrote:

It is recommended to insert jQuery elements like this in a component:

this.$().fullCalender

I tried this but always get “fullcalendar is not a function”.

If inserted without ‘this’, it’s working as expected:

component JS:

export default Component.extend({
  didInsertElement() {
    $('.jquerycal').fullCalendar({
      events: this.get('events')
  },
  willDestroyElement() {
    $('.jquerycal').fullCalendar().destroy();
  }
});

component template:

<div class="jquerycal"></div>

I noticed that …

$().fullCalendar

… without an selector will also not work.

I included fullcalender with app.import:

app.import('vendor/plugins/fullcalendar/fullcalendar.min.js');

Posts: 2

Participants: 2

Read full topic

Viewing all 4749 articles
Browse latest View live


Latest Images