AnsweredAssumed Answered

Can Accessor not be used as Singleton?

Question asked by btfou on Mar 17, 2017
Latest reply on May 26, 2017 by btfou

I'm playing around with Accessor and trying to return a Singleton but requiring the module anytime after first require on booting the app just returns an Object.

 

// returns Singleton
define([
  'dojo/_base/declare',
  'dojo/Stateful',
  'dojo/Evented'
], function (
  declare,
  Stateful,
  Evented
) {
  var _instance = null;

  var Model = declare([Stateful, Evented], {
  // stuff
  });

  if (!_instance) {
    _instance = new Model();
  }
  return _instance;
});

// returns Object
define([
  'esri/core/Accessor',
  'dojo/Evented'
], function (
  Accessor,
  Evented
) {
  var _instance = null;

  var Model = Accessor.createSubclass([Evented], {
  // stuff
  });

  if (!_instance) {
    _instance = new Model();
  }
  return _instance;
});

Outcomes