logo
down
shadow

run a function when an Ember.Object is created


run a function when an Ember.Object is created

By : user2955195
Date : November 22 2020, 10:38 AM
will help you Functions don't really have an on method, perhaps you are confusing them with observers?
code :
fullNameChanged: function() {
   // deal with the change
}.observes('fullName').on('init')
  init: function() {
    this._super();
    this.checkEnvironment();
  },


Share : facebook icon twitter icon
Deleting an Ember.Object created within an Ember.View

Deleting an Ember.Object created within an Ember.View


By : htothek
Date : March 29 2020, 07:55 AM
it helps some times You could have an action which sets the view's person to null.
So in your view template you'd have something like:
code :
<a href="#" {{action logout}}>Log out</a>
logout: function() {
    this.set("person", null);
}
Passing current router's model into a created object in Ember.js

Passing current router's model into a created object in Ember.js


By : John Maroudas
Date : March 29 2020, 07:55 AM
hope this fix your issue I'd probably build up some sort of scheduler whose purpose was to handle the reloading, scheduling etc.
Then you could subscribe to the reloader and unsubscribe when it's time to stop it. Then you can avoid having a model in multiple places reloading.
Ember Model Object created but not showing in template

Ember Model Object created but not showing in template


By : Michel Manias
Date : March 29 2020, 07:55 AM
With these it helps First off user isn't anywhere in scope there. Your model hook only returns a list of favorites.
Secondly, I'm not sure how this method is working, I believe it should be crashing:
code :
createUser: function(user, arr) {
    var record;
    record = this.store.createRecord('user', {});
    record.setProperties({
        id: user.id,
        username: user.username,
    });
    // arr here is the favorite record, not an array, how is this
    // not crashing?
    arr.pushObject(record);
    return record;
},
model: function(params) {
    var artist, favoriteList, self, ret;
    self = this;
    artist = params.artist;
    ret = [];
    this.controllerFor('application').set('artistName', artist);

    return new Ember.RSVP.Promise(function(resolve, reject) {
        return SC.get("/users/" + 'mannaio' + "/favorites", {
            limit: 40
        }, function(favorites) {
            if (favorites.length) {
                favorites.forEach(function(item, index, arr) {
                    var favorite;
                    favorite = self.createFavoritelist(item);
                    ret.push(favorite);
                    favorite.user = self.createUser(item.user);
                });
            }
            resolve(ret);
        });
    });
},

createFavoritelist: function(favorite) {
    return this.store.createRecord('favorite', {
        id: favorite.id,
        title: favorite.title,
        artwork_url: favorite.artwork_url,
        genre: favorite.genre,
    });
},

createUser: function(user) {
    return this.store.createRecord('user', {
        id: user.id,
        username: user.username,
    });
},
<section class="streaming__favorites">
    {{#each favorite in sortedFavorites}}
            <article class="streaming__favorites__song">
                <span>{{favorite.title}}</span>
                <span>{{favorite.genre}}</span>
                <span>{{favorite.user.username}}</span>
            </article>
    {{/each}}
</section>
ember.js ember-data initiale state of new created model record

ember.js ember-data initiale state of new created model record


By : InwCeam
Date : November 19 2020, 09:01 AM
Hope that helps The only solution I found is test if the object is new. If is it, re-create a new one.
If not, I call the rollbackAttributes().
code :
isChanged : function() {
            return this._internalModel.hasChangedAttributes();
        }
Javascript created object property values undefined after calling another function with created object

Javascript created object property values undefined after calling another function with created object


By : moataz-mo
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Object.create is a little confusing - you can't use a normal object as the second parameter, it has to be an object of 'property descriptors'. To work properly your code would need to be formatted along these lines:
code :
const notificationSocketEventHandler = Object.create(socketHandlerProto, {
  'validators': {
    value: {
     'created': {
          value: []
      },
      'destroyed': {
          value: []
      },
      'loadedFromSocket': {
           value: []
      }
    }    
  }
});
const notificationSocketEventHandler = {
   created: [],
   destroyed: [],
   etc...
}
var SocketHandler = function {
    this.created = [];
    this.destroyed = []
    etc...
}

const notificationSocketEventHandler = new SocketHandler
var SocketHandler = {};
SocketHandler.prototype.created = [];
SocketHandler.prototype.destroyed = [];
etc...
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org