From b73b824e55560a98ccc1e814284286a3bddeccc9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 27 May 2016 11:43:35 -0700 Subject: [PATCH 1/4] [API] Add EventEmitter dep --- bower.json | 3 ++- main.js | 4 ++++ test-main.js | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 7c913754cf..c10b8e49e2 100644 --- a/bower.json +++ b/bower.json @@ -18,6 +18,7 @@ "node-uuid": "^1.4.7", "comma-separated-values": "^3.6.4", "FileSaver.js": "^0.0.2", - "zepto": "^1.1.6" + "zepto": "^1.1.6", + "eventemitter3": "^1.2.0" } } diff --git a/main.js b/main.js index 4fba458a4c..579b33dc4f 100644 --- a/main.js +++ b/main.js @@ -28,6 +28,7 @@ requirejs.config({ "angular-route": "bower_components/angular-route/angular-route.min", "csv": "bower_components/comma-separated-values/csv.min", "es6-promise": "bower_components/es6-promise/promise.min", + "EventEmitter": "bower_components/eventemitter3/index", "moment": "bower_components/moment/moment", "moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format", "saveAs": "bower_components/FileSaver.js/FileSaver.min", @@ -43,6 +44,9 @@ requirejs.config({ "angular-route": { "deps": ["angular"] }, + "EventEmitter": { + "exports": "EventEmitter" + }, "moment-duration-format": { "deps": ["moment"] }, diff --git a/test-main.js b/test-main.js index 90da6dabb9..ee29bd7f51 100644 --- a/test-main.js +++ b/test-main.js @@ -48,6 +48,7 @@ requirejs.config({ "angular-route": "bower_components/angular-route/angular-route.min", "csv": "bower_components/comma-separated-values/csv.min", "es6-promise": "bower_components/es6-promise/promise.min", + "EventEmitter": "bower_components/eventemitter3/index", "moment": "bower_components/moment/moment", "moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format", "saveAs": "bower_components/FileSaver.js/FileSaver.min", @@ -64,6 +65,9 @@ requirejs.config({ "angular-route": { "deps": [ "angular" ] }, + "EventEmitter": { + "exports": "EventEmitter" + }, "moment-duration-format": { "deps": [ "moment" ] }, From 0c660238f2eb57d4bb271d9ded170c1725ec1c29 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 27 May 2016 11:49:43 -0700 Subject: [PATCH 2/4] [API] Add MCT class --- index.html | 2 +- main.js | 18 +++++++++++------- src/MCT.js | 13 +++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/MCT.js diff --git a/index.html b/index.html index e16b096abb..c5ff002029 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@ './example/imagery/bundle', './example/eventGenerator/bundle', './example/generator/bundle' - ], mct.run.bind(mct)); + ], mct.start.bind(mct)); }); diff --git a/main.js b/main.js index 579b33dc4f..561c6e8b79 100644 --- a/main.js +++ b/main.js @@ -62,6 +62,7 @@ requirejs.config({ define([ './platform/framework/src/Main', 'legacyRegistry', + './src/MCT', './platform/framework/bundle', './platform/core/bundle', @@ -97,11 +98,14 @@ define([ './platform/search/bundle', './platform/status/bundle', './platform/commonUI/regions/bundle' -], function (Main, legacyRegistry) { - return { - legacyRegistry: legacyRegistry, - run: function () { - return new Main().run(legacyRegistry); - } - }; +], function (Main, legacyRegistry, MCT) { + var mct = new MCT(); + + mct.legacyRegistry = legacyRegistry; + mct.run = mct.start; + mct.on('start', function () { + return new Main().run(legacyRegistry); + }); + + return mct; }); diff --git a/src/MCT.js b/src/MCT.js new file mode 100644 index 0000000000..4999e5e548 --- /dev/null +++ b/src/MCT.js @@ -0,0 +1,13 @@ +define(['EventEmitter'], function (EventEmitter) { + function MCT() { + EventEmitter.call(this); + } + + MCT.prototype = Object.create(EventEmitter.prototype); + + MCT.prototype.start = function () { + this.emit('start'); + }; + + return MCT; +}); From a6996df3df68964ee2dff7cf311ea1e7ec662b3f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 27 May 2016 13:17:16 -0700 Subject: [PATCH 3/4] [API] Begin moving out type --- tutorials/todo/bundle.js | 12 ------------ tutorials/todo/todo.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 tutorials/todo/todo.js diff --git a/tutorials/todo/bundle.js b/tutorials/todo/bundle.js index 31d0ed151c..b56d2cdfdf 100644 --- a/tutorials/todo/bundle.js +++ b/tutorials/todo/bundle.js @@ -9,18 +9,6 @@ define([ "name": "To-do Plugin", "description": "Allows creating and editing to-do lists.", "extensions": { - "types": [ - { - "key": "example.todo", - "name": "To-Do List", - "glyph": "2", - "description": "A list of things that need to be done.", - "features": ["creation"], - "model": { - "tasks": [] - } - } - ], "views": [ { "key": "example.todo", diff --git a/tutorials/todo/todo.js b/tutorials/todo/todo.js new file mode 100644 index 0000000000..51bbba8fe1 --- /dev/null +++ b/tutorials/todo/todo.js @@ -0,0 +1,19 @@ +define(function () { + return function todoPlugin(mct) { + var todoType = new mct.Type({ + metadata: { + label: "To-Do List", + glyph: "2", + description: "A list of things that need to be done." + }, + initialize: function (model) { + model.tasks = []; + }, + creatable: true + }); + + mct.type('example.todo', todoType); + + return mct; + }; +}); From c4fec1af6aa12f225352813dcbf8a747a10fe23d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 27 May 2016 13:31:30 -0700 Subject: [PATCH 4/4] [API] Move type toward a newer API --- index.html | 7 ++++++- src/MCT.js | 20 +++++++++++++++++++- src/api/Type.js | 43 +++++++++++++++++++++++++++++++++++++++++++ src/api/api.js | 9 +++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 src/api/Type.js create mode 100644 src/api/api.js diff --git a/index.html b/index.html index c5ff002029..301ade4506 100644 --- a/index.html +++ b/index.html @@ -31,10 +31,15 @@ diff --git a/src/MCT.js b/src/MCT.js index 4999e5e548..3b66611451 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -1,11 +1,29 @@ -define(['EventEmitter'], function (EventEmitter) { +define([ + 'EventEmitter', + 'legacyRegistry', + './api/api' +], function (EventEmitter, legacyRegistry, api) { function MCT() { EventEmitter.call(this); + this.legacyBundle = { extensions: {} }; } MCT.prototype = Object.create(EventEmitter.prototype); + Object.keys(api).forEach(function (k) { + MCT.prototype[k] = api[k]; + }); + + MCT.prototype.type = function (key, type) { + var legacyDef = type.toLegacyDefinition(); + legacyDef.key = key; + this.legacyBundle.extensions.types = + this.legacyBundle.extensions.types || []; + this.legacyBundle.extensions.types.push(legacyDef); + }; + MCT.prototype.start = function () { + legacyRegistry.register('adapter', this.legacyBundle); this.emit('start'); }; diff --git a/src/api/Type.js b/src/api/Type.js new file mode 100644 index 0000000000..6ce5d29a86 --- /dev/null +++ b/src/api/Type.js @@ -0,0 +1,43 @@ +define(function () { + /** + * @typedef TypeDefinition + * @property {Metadata} metadata displayable metadata about this type + * @property {function (object)} [initialize] a function which initializes + * the model for new domain objects of this type + * @property {boolean} [creatable] true if users should be allowed to + * create this type (default: false) + */ + + /** + * + * @param {TypeDefinition} definition + * @constructor + */ + function Type(definition) { + this.definition = definition; + } + + /** + * Get a definition for this type that can be registered using the + * legacy bundle format. + * @private + */ + Type.prototype.toLegacyDefinition = function () { + var def = {}; + def.name = this.definition.metadata.label; + def.glyph = this.definition.metadata.glyph; + def.description = this.definition.metadata.description; + + if (this.definition.initialize) { + def.model = {}; + this.definition.initialize(def.model); + } + + if (this.definition.creatable) { + def.features = ['creation']; + } + return def; + }; + + return Type; +}); diff --git a/src/api/api.js b/src/api/api.js new file mode 100644 index 0000000000..b64b1f578d --- /dev/null +++ b/src/api/api.js @@ -0,0 +1,9 @@ +define([ + './Type' +], function ( + Type +) { + return { + Type: Type + }; +});