Can a mixin use an object that uses a mixin?


#1

I have a mixin that calls into a model class that uses a mixin

Problem is the model doesn’t seem to have access to the functions provided by the mixin.

Is this possible?

To expand on this, I am continuing my work to reverse engineer the discourse header.

I have my header controller:

import Ember from 'ember';
import HasCurrentUser from 'bootstrap-test/mixins/has-current-user';

export default Ember.Controller.extend(HasCurrentUser, {});

my has-current-user mixin:

import Ember from 'ember';
import User from 'bootstrap-test/models/user';

export default Ember.Mixin.create({
  currentUser: function() {
    var user = User.current();
    return user;
  }.property().volatile()
});

And my user model:

import DS from 'ember-data';
import Singleton from 'bootstrap-test/mixins/singleton';
var user = DS.Model.extend({});
user.reopen(Singleton, {
  createCurrent: function() {
    var userJson = PreloadStore.get('currentUser');
    if (userJson) { return user.create(userJson); }
    return null;
  },
});

export default user;

And the singleton class provided by discourse (comments removed for brevity):

import Ember from 'ember';

export default Ember.Mixin.create({
  current: function() {
    if (!this._current) {
      this._current = this.createCurrent();
    }

    return this._current;
  },

  createCurrent: function() {
    return this.create({});
  },

  currentProp: function(property, value) {
    var instance = this.current();
    if (!instance) { return; }

    if (typeof(value) !== "undefined") {
      instance.set(property, value);
      return value;
    } else {
      return instance.get(property);
    }
  },

  resetCurrent: function(val) {
    this._current = val;
  }
});

I would expect to be able to call current() on the User:

User.current();

And it would find the implementation of current() on the Singleton mixin - but current is undefined?


#2

I fixed this by putting the reopenClass (not reopen) stuff into an initializer