Remove the unnecessary construction of new services.

This commit is contained in:
Sean Lip
2016-06-09 19:10:34 -07:00
parent c6517bc777
commit 11b49930f9
7 changed files with 22 additions and 15 deletions

View File

@@ -55,10 +55,10 @@ blocklyApp.AppView = ng.core
`,
directives: [blocklyApp.ToolboxView, blocklyApp.WorkspaceView],
pipes: [blocklyApp.TranslatePipe],
// ClipboardService declared here so that all components are using the same
// instance of the clipboard.
// The clipboard and utils services are declared here, so that all
// components in the application use the same instance of the service.
// https://www.sitepoint.com/angular-2-components-providers-classes-factories-values/
providers: [blocklyApp.ClipboardService]
providers: [blocklyApp.ClipboardService, blocklyApp.UtilsService]
})
.Class({
constructor: function() {}

View File

@@ -25,6 +25,7 @@
blocklyApp.ClipboardService = ng.core
.Class({
constructor: function() {
blocklyApp.debug && console.log('Clipboard service constructed');
this.clipboardBlockXml_ = null;
this.clipboardBlockSuperiorConnection_ = null;
this.clipboardBlockNextConnection_ = null;

View File

@@ -62,8 +62,7 @@ blocklyApp.FieldView = ng.core
</li>
`,
inputs: ['field', 'level', 'index', 'parentId'],
pipes: [blocklyApp.TranslatePipe],
providers: [blocklyApp.TreeService, blocklyApp.UtilsService]
pipes: [blocklyApp.TranslatePipe]
})
.Class({
constructor: [blocklyApp.UtilsService, function(_utilsService) {

View File

@@ -105,13 +105,14 @@ blocklyApp.ToolboxTreeView = ng.core
}), blocklyApp.FieldView],
inputs: [
'block', 'displayBlockMenu', 'level', 'index', 'tree', 'noCategories'],
pipes: [blocklyApp.TranslatePipe],
providers: [blocklyApp.TreeService, blocklyApp.UtilsService]
pipes: [blocklyApp.TranslatePipe]
})
.Class({
constructor: [blocklyApp.ClipboardService, blocklyApp.TreeService,
blocklyApp.UtilsService,
function(_clipboardService, _treeService, _utilsService) {
constructor: [
blocklyApp.ClipboardService, blocklyApp.TreeService, blocklyApp.UtilsService,
function(_clipboardService, _treeService, _utilsService) {
// ClipboardService and UtilsService are app-wide singleton services.
// TreeService is from the parent ToolboxView component.
this.infoBlocks = Object.create(null);
this.clipboardService = _clipboardService;
this.treeService = _treeService;

View File

@@ -19,6 +19,8 @@
/**
* @fileoverview Angular2 Service that handles all tree keyboard navigation.
* A separate TreeService is constructed for each tree in the application.
*
* @author madeeha@google.com (Madeeha Ghori)
*/

View File

@@ -18,8 +18,10 @@
*/
/**
* @fileoverview Angular2 Service with functions required by multiple
* components.
* @fileoverview Angular2 utility service for multiple components. All
* functions in this service should be stateless, since this is a singleton
* service that is used for the entire application.
*
* @author madeeha@google.com (Madeeha Ghori)
*/
@@ -28,6 +30,7 @@ var blocklyApp = {};
blocklyApp.UtilsService = ng.core
.Class({
constructor: function() {
blocklyApp.debug && console.log('Utils service constructed');
},
generateUniqueId: function() {
return 'blockly-' + Blockly.genUid();

View File

@@ -117,11 +117,12 @@ blocklyApp.WorkspaceTreeView = ng.core
[level]="level">
</tree-view>
`,
directives: [ng.core.forwardRef(
function() { return blocklyApp.WorkspaceTreeView; }), blocklyApp.FieldView],
directives: [ng.core.forwardRef(function() {
return blocklyApp.WorkspaceTreeView;
}), blocklyApp.FieldView],
inputs: ['block', 'isTopBlock', 'topBlockIndex', 'level', 'parentId'],
pipes: [blocklyApp.TranslatePipe],
providers: [blocklyApp.TreeService, blocklyApp.UtilsService],
providers: [blocklyApp.TreeService],
})
.Class({
constructor: [