Use a lazy getter to access IconServices singleton
References: atom/fuzzy-finder@2c1fe65
MODIFY
lib/find.coffee
lib/find.coffee
@@ -4,7 +4,7 @@ SelectNext = require './select-next'
{History, HistoryCycler} = require './history'
FindOptions = require './find-options'
BufferSearch = require './buffer-search'
-IconServices = require './icon-services'
+getIconServices = require './get-icon-services'
FindView = require './find-view'
ProjectFindView = require './project-find-view'
ResultsModel = require './project/results-model'
@@ -118,14 +118,14 @@ module.exports =
selectNextObjectForEditorElement(this).skipCurrentSelection()
consumeElementIcons: (service) ->
- IconServices.setElementIcons service
+ getIconServices().setElementIcons service
new Disposable =>
- IconServices.resetElementIcons()
+ getIconServices().resetElementIcons()
consumeFileIcons: (service) ->
- IconServices.setFileIcons service
+ getIconServices().setFileIcons service
new Disposable ->
- IconServices.resetFileIcons()
+ getIconServices().resetFileIcons()
toggleAutocompletions: (value) ->
if not @findView?

RENAME
lib/icon-services.js
lib/get-icon-services.js
const DefaultFileIcons = require('./default-file-icons')
const {Emitter, CompositeDisposable} = require('atom')
+let iconServices
+module.exports = function () {
+ if (!iconServices) iconServices = new IconServices()
+ return iconServices
+}
+
class IconServices {
constructor () {
this.emitter = new Emitter()
@@ -57,5 +63,3 @@ class IconServices {
return iconClass
}
}
-
-module.exports = new IconServices()

MODIFY
lib/project/result-view.js
lib/project/result-view.js
-const IconServices = require('../icon-services');
+const getIconServices = require('../get-icon-services');
const MatchView = require('./match-view');
const path = require('path');
const etch = require('etch');
@@ -98,7 +98,7 @@ class ResultView {
this.selectedMatchIndex === -1
);
- const iconClass = IconServices.getIconClasses(this)
+ const iconClass = getIconServices().getIconClasses(this)
return (
$.li(

MODIFY
spec/results-view-spec.js
spec/results-view-spec.js
@@ -6,7 +6,7 @@ const temp = require('temp');
const fs = require('fs');
const etch = require('etch');
const ResultsPaneView = require('../lib/project/results-pane');
-const IconServices = require('../lib/icon-services');
+const getIconServices = require('../lib/get-icon-services');
const {beforeEach, it, fit, ffit, fffit} = require('./async-spec-helpers')
global.beforeEach(function() {

Use a lazy getter to access IconServices singleton

References: atom/fuzzy-finder@2c1fe65