<commit_before>define([
	"dojo/_base/declare",	// declare
	"rishson/Globals",	//TOPIC_NAMESPACE
	"dojo/_base/lang",	//mixin
	"dojo/topic",	// publish/subscribe
	"dojo/_base/array",	// forEach, indexOf
	"dojo/_base/Deferred"	//constructor
], function (declare, Globals, lang, topic, arrayUtil, Deferred) {

	/**
	 * @class
	 * @name rishson.Base
	 * @description Base class for all objects
	 */
	return declare('rishson.Base', null, {
		/**
		 * @field
		 * @name rishson.Base.isInitialised
		 * @type {boolean}
		 * @description Is the widget initialised? Default to false - duh.
		 */
		isInitialised: false,

		/**
		 * @field
		 * @name rishson.Base._parentTopicNamespace
		 * @type {string}
		 * @description This namespace is prepended to every topic name used by a derived class
		 */
		parentTopicNamespace: '',

		/**
		 * @field
		 * @name rishson.Base.pubList
		 * @type {string}
		 * @description Object that contains the list of topics that any derived class can publish
		 */
		pubList: null,

		/**
		 * @field
		 * @name rishson.Base.subList
		 * @type {string}
		 * @description Object that contains the list of topics that any derived class can listen out for
		 */
		subList: null,

		/**
		 * @field
		 * @private
		 * @name rishson.Base._id
		 * @type {string}
		 * @description The unique id of a widget created with this base class.
		 */
		_id: null,

		/**
		 * @constructor
		 */
		constructor: function (args) {
			this.pubList = {};
			if (args) {
				lang.mixin(this, args);

				if (!this._supportingWidgets) {
					this._supportingWidgets = [];	//anything that does not derive from _Widget will not have this
				}

				this.addTopic('INITIALISED', Globals.CHILD_INTIALISED_TOPIC_NAME);
			}
		},

		/**
		 * @function
		 * @name rishson.Base.createTopicNamespace
		 * @param namespace {string} a class namespace (. separated) that will be turned into a topic (/ separated)
		 * @description Replace all '.' with '/'
		 */
		createTopicNamespace: function (namespace) {
			/*any derived widget can publish events on their own namespace so construct the widget namespace from
			 the declared class, but replace the . to be a / so it is standard topic conventions*/
			return '/' + namespace.replace(/\./g, '/');
		},

		/**
		 * @function
		 * @name rishson.Base.addTopic
		 * @param topicRef {string} the object property (usually CAPITALISED) of the topic in the pubList
		 * @param topicName {string} the name of topic
		 * @param makeGlobal {boolean=} makeGlobal if true use the global topic namespace
		 * @description Syntactic sugar to add items to a class's pubList.
		 */
		addTopic: function (topicRef, topicName, makeGlobal) {
			if (!makeGlobal) {
				this.pubList[topicRef] = this.parentTopicNamespace + topicName;
			} else {
				this.pubList[topicRef] = Globals.TOPIC_NAMESPACE + topicName;
			}
		},

		/**
		 * @function
		 * @name rishson.Base.capitaliseTopicName
		 * @param {string} topic a name of a topic to capitalise.
		 * @description capitalise the first letter of a topic.
		 * e.g. /hello/i/am/a/topicName would become Hello/I/Am/A/TopicName
		 */
		capitaliseTopicName: function (topic) {
			return topic.replace(/\b[a-z]/g, function (w) {
				return w.toUpperCase();
			});
		},

		/**
		 * @function
		 * @name rishson.Base.asyncRequire
		 * @description Instantiate a widget asynchronously within the application flow.
		 * If the requiring widget is a controller (inherits from rishson.control._Controller) then it will also
		 * autowire the widget.
		 * @param {Object} widget
		 * @return {Object} deferred
		 */
		asyncRequire: function (widget) {
			var deferred = new Deferred();

			require([widget], lang.hitch(this, function (WidgetConstructor) {
				var widgetInstance = this.adopt(WidgetConstructor, {});
				deferred.resolve(widgetInstance);
			}));
			return deferred;<commit_msg>Added ability to pass node and params to asyncRequire.<commit_after>define([
	"dojo/_base/declare",	// declare
	"rishson/Globals",	//TOPIC_NAMESPACE
	"dojo/_base/lang",	//mixin
	"dojo/topic",	// publish/subscribe
	"dojo/_base/array",	// forEach, indexOf
	"dojo/_base/Deferred"	//constructor
], function (declare, Globals, lang, topic, arrayUtil, Deferred) {

	/**
	 * @class
	 * @name rishson.Base
	 * @description Base class for all objects
	 */
	return declare('rishson.Base', null, {
		/**
		 * @field
		 * @name rishson.Base.isInitialised
		 * @type {boolean}
		 * @description Is the widget initialised? Default to false - duh.
		 */
		isInitialised: false,

		/**
		 * @field
		 * @name rishson.Base._parentTopicNamespace
		 * @type {string}
		 * @description This namespace is prepended to every topic name used by a derived class
		 */
		parentTopicNamespace: '',

		/**
		 * @field
		 * @name rishson.Base.pubList
		 * @type {string}
		 * @description Object that contains the list of topics that any derived class can publish
		 */
		pubList: null,

		/**
		 * @field
		 * @name rishson.Base.subList
		 * @type {string}
		 * @description Object that contains the list of topics that any derived class can listen out for
		 */
		subList: null,

		/**
		 * @field
		 * @private
		 * @name rishson.Base._id
		 * @type {string}
		 * @description The unique id of a widget created with this base class.
		 */
		_id: null,

		/**
		 * @constructor
		 */
		constructor: function (args) {
			this.pubList = {};
			if (args) {
				lang.mixin(this, args);

				if (!this._supportingWidgets) {
					this._supportingWidgets = [];	//anything that does not derive from _Widget will not have this
				}

				this.addTopic('INITIALISED', Globals.CHILD_INTIALISED_TOPIC_NAME);
			}
		},

		/**
		 * @function
		 * @name rishson.Base.createTopicNamespace
		 * @param namespace {string} a class namespace (. separated) that will be turned into a topic (/ separated)
		 * @description Replace all '.' with '/'
		 */
		createTopicNamespace: function (namespace) {
			/*any derived widget can publish events on their own namespace so construct the widget namespace from
			 the declared class, but replace the . to be a / so it is standard topic conventions*/
			return '/' + namespace.replace(/\./g, '/');
		},

		/**
		 * @function
		 * @name rishson.Base.addTopic
		 * @param topicRef {string} the object property (usually CAPITALISED) of the topic in the pubList
		 * @param topicName {string} the name of topic
		 * @param makeGlobal {boolean=} makeGlobal if true use the global topic namespace
		 * @description Syntactic sugar to add items to a class's pubList.
		 */
		addTopic: function (topicRef, topicName, makeGlobal) {
			if (!makeGlobal) {
				this.pubList[topicRef] = this.parentTopicNamespace + topicName;
			} else {
				this.pubList[topicRef] = Globals.TOPIC_NAMESPACE + topicName;
			}
		},

		/**
		 * @function
		 * @name rishson.Base.capitaliseTopicName
		 * @param {string} topic a name of a topic to capitalise.
		 * @description capitalise the first letter of a topic.
		 * e.g. /hello/i/am/a/topicName would become Hello/I/Am/A/TopicName
		 */
		capitaliseTopicName: function (topic) {
			return topic.replace(/\b[a-z]/g, function (w) {
				return w.toUpperCase();
			});
		},

		/**
		 * @function
		 * @name rishson.Base.asyncRequire
		 * @description Instantiate a widget asynchronously within the application flow.
		 * If the requiring widget is a controller (inherits from rishson.control._Controller) then it will also
		 * autowire the widget.
		 * @param {Object} widget
		 * @param {Object=} props
		 * @param {Object=} node
		 * @return {Object} deferred
		 */
		asyncRequire: function (widget, props, node) {
			var deferred = new Deferred();

			require([widget], lang.hitch(this, function (WidgetConstructor) {
				var widgetInstance = this.adopt(WidgetConstructor, props, node);
				deferred.resolve(widgetInstance);
			}));
			return deferred;
{'fraction_non_alphanumeric': 0.11982626469085335, 'fraction_numerical': 0.0, 'mean_word_length': 3.1621477937267413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2094741', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2308, 'n_words': 741}