# StructureJS Snippets
# for Atom
# .js filetype
#
# Paste into:
# Atom > Open Your Snippets
#
# Shortcuts
# DOMElement: viewClass
# BaseModel: baseModel
# Stage: stageClass
# Property: property
# Method: method
# Import: import
# Extend: extendClass
# Event: eventClass

".source.js":
  "View":
   prefix: "viewClass"
   body: """
define(function(require, exports, module) { // jshint ignore:line
    'use strict';

    // Imports
    var Extend = require('structurejs/util/Extend');
    var DOMElement = require('structurejs/display/DOMElement');

    /**
     * TODO: YUIDoc_comment
     *
     * @class ${1:Class}
     * @extends DOMElement
     * @constructor
     **/
    var ${1:Class} = (function () {

        var _super = Extend (${1:Class}, DOMElement); // jshint ignore:line

        function ${1:Class} () { // jshint ignore:line
            _super.call(this);

 			$2
        }

        /**
         * @overridden DOMElement.create
         */
        ${1:Class}.prototype.create = function () {
            _super.prototype.create.call(this);

            // Create or setup objects in this parent class.
        };

        /**
         * @overridden DOMElement.enable
         */
        ${1:Class}.prototype.enable = function () {
            if (this.isEnabled === true) { return; }

            // Enable the child objects and/or add any event listeners.

            _super.prototype.enable.call(this);
        };

        /**
         * @overridden DOMElement.disable
         */
        ${1:Class}.prototype.disable = function () {
            if (this.isEnabled === false) { return; }

            // Disable the child objects and/or remove any event listeners.

            _super.prototype.disable.call(this);
        };

        /**
         * @overridden DOMElement.layout
         */
        ${1:Class}.prototype.layout = function () {
            // Layout or update the child objects in this parent class.
        };

        /**
         * @overridden DOMElement.destroy
         */
        ${1:Class}.prototype.destroy = function () {
            this.disable();

            // Call destroy on any child objects.
            // This super method will also null out your properties for garbage collection.

            _super.prototype.destroy.call(this);
        };

        return ${1:Class};

    })();

    module.exports = ${1:Class};

});
   """
  " Base Model":
   prefix: "baseModel"
   body: """
define(function(require, exports, module) { // jshint ignore:line
    'use strict';

    // Imports
    var Extend = require('structurejs/util/Extend');
    var BaseModel = require('structurejs/model/BaseModel');

    /**
     * TODO: YUIDoc_comment
     *
     * @class ${1:Class}
     * @extends BaseModel
     * @constructor
     **/
    var ${1:Class} = (function () {

        var _super = Extend (${1:Class}, BaseModel); // jshint ignore:line

        function ${1:Class} () { // jshint ignore:line
            _super.call(this);

            if (data) {
                this.update(data);
            }
        }

        /**
        * @overridden BaseModel.update
        */
        ${1:Class}.prototype.update = function (data) {
            _super.prototype.update.call(this, data);

            // Override any values after the default super update method has set the values.
        };

        return ${1:Class};

    })();

    module.exports = ${1:Class};

});
   """
  "Stage":
   prefix: "stageClass"
   body: """
define(function(require, exports, module) { // jshint ignore:line
    'use strict';

    // Imports
    var Extend = require('structurejs/util/Extend');
    var Stage = require('structurejs/display/Stage');

    /**
     * TODO: YUIDoc_comment
     *
     * @class ${1:Class}
     * @extends Stage
     * @constructor
     **/
    var ${1:Class} = (function () {

        var _super = Extend (${1:Class}, Stage); // jshint ignore:line

        function ${1:Class} () { // jshint ignore:line
            _super.call(this);

 			$2
        }

        /**
         * @overridden Stage.create
         */
        ${1:Class}.prototype.create = function () {
            _super.prototype.create.call(this);

            // Create or setup objects in this parent class.
        };

        /**
         * @overridden Stage.enable
         */
        ${1:Class}.prototype.enable = function () {
            if (this.isEnabled === true) { return; }

            // Enable the child objects and/or add any event listeners.

            _super.prototype.enable.call(this);
        };

        /**
         * @overridden Stage.disable
         */
        ${1:Class}.prototype.disable = function () {
            if (this.isEnabled === false) { return; }

            // Disable the child objects and/or remove any event listeners.

            _super.prototype.disable.call(this);
        };

        /**
         * @overridden Stage.layout
         */
        ${1:Class}.prototype.layout = function () {
            // Layout or update the objects in this parent class.
        };

        /**
         * @overridden Stage.destroy
         */
        ${1:Class}.prototype.destroy = function () {
            this.disable();

            // Call destroy on any child objects.
            // This super method will also null out your properties for garbage collection.

            _super.prototype.destroy.call(this);
        };

        return ${1:Class};

    })();

    module.exports = ${1:Class};

});
"""
  "Property":
    prefix: "property"
    body: """
/**
 * @property ${1:propertyName}
 * @type {${2:propertyType}}
 * @${3:accessType}
 */
this.${1} = ${4:null};
    """
  "Method":
    prefix: "method"
    body: """
/**
 * @TODO: YUIDoc_comment
 *
 * @method ${1:methodName}
 * @${2:accessType}
 */
${3:ClassName}.prototype.${1} = function ($4) {
    $5
};
    """
  "Import":
    prefix: "import"
    body: "var ${1:ClassName} = require('${2:path}/${1}');"
  "Extend":
    prefix: "extendClass"
    body: """
/**
* @fileOverview
* ${1:Class}
*/
define(function(require, exports, module) { // jshint ignore:line
    'use strict';

    // Imports
    var Extend = require('structurejs/util/Extend');
    var ${2} = require('path/${2}');

    /**
     * TODO: YUIDoc_comment
     *
     * @class ${1:Class}
     * @extends ${2}
     * @constructor
     **/
    var ${1:Class} = (function () {

        var _super = Extend (${1:Class}); // jshint ignore:line

        function ${1:Class} () { // jshint ignore:line
            _super.call(this);
        }

        return ${1:Class};

    })();

    module.exports = ${1:Class};

});
    """
  "Event":
    prefix: "eventClass"
    body: """
define(function (require, exports, module) { // jshint ignore:line
    'use strict';

    // Imports
    var Extend = require('structurejs/util/Extend');
    var BaseEvent = require('structurejs/event/BaseEvent');

    /**
     * TODO: YUIDoc_comment
     *
     * @class ${1:Class}
     * @extends BaseEvent
     * @constructor
     **/
    var ${1:Class} = (function () {

        /**
         * This is an example of an event type.
         * Go ahead and rename or remove this.
         *
         * @event EXAMPLE
         * @type {string}
         * @static
         */
        ${1:Class}.EXAMPLE = '${1:Class}.example';

      var _super = Extend(${1:Class}, BaseEvent);

          function ${1:Class}() {
              _super.call(this);
          }

          return ${1:Class};

    })();

    module.exports = ${1:Class};

});
        """
