Rename ViewRegistry to ViewFactory

The new ViewRegistry will be focused only on storing model::view
associations, leaving the global factory to focus on creating them.
Esse commit está contido em:
Nathan Sobo
2014-11-30 15:49:49 -07:00
commit 05e7e9fc1d
4 arquivos alterados com 32 adições e 32 exclusões
@@ -1,17 +1,17 @@
ViewRegistry = require '../src/view-registry'
ViewFactory = require '../src/view-factory'
{View} = require '../src/space-pen-extensions'
describe "ViewRegistry", ->
registry = null
describe "ViewFactory", ->
factory = null
beforeEach ->
registry = new ViewRegistry
factory = new ViewFactory
describe "::createView(object, params)", ->
describe "when passed a DOM node", ->
it "returns the given DOM node", ->
node = document.createElement('div')
expect(registry.createView(node)).toBe node
expect(factory.createView(node)).toBe node
describe "when passed a SpacePen view", ->
it "returns the root node of the view with a __spacePenView property pointing at the SpacePen view", ->
@@ -19,7 +19,7 @@ describe "ViewRegistry", ->
@content: -> @div "Hello"
view = new TestView
node = registry.createView(view)
node = factory.createView(view)
expect(node.textContent).toBe "Hello"
expect(node.__spacePenView).toBe view
@@ -36,17 +36,17 @@ describe "ViewRegistry", ->
model = new TestModel
registry.addViewProvider
factory.addViewProvider
modelConstructor: TestModel
viewConstructor: TestView
view = registry.createView(model, a: 1)
view = factory.createView(model, a: 1)
expect(view instanceof TestView).toBe true
expect(view.params.a).toBe 1
expect(view.params.model).toBe model
subclassModel = new TestModelSubclass
view2 = registry.createView(subclassModel)
view2 = factory.createView(subclassModel)
expect(view2 instanceof TestView).toBe true
expect(view2.params.model).toBe subclassModel
@@ -56,7 +56,7 @@ describe "ViewRegistry", ->
class TestView
initialize: (@params) ->
registry.addViewProvider
factory.addViewProvider
modelConstructor: TestModel
createView: (params) ->
view = new TestView
@@ -64,7 +64,7 @@ describe "ViewRegistry", ->
view
model = new TestModel
view = registry.createView(model, a: 1)
view = factory.createView(model, a: 1)
expect(view instanceof TestView).toBe true
expect(view.params.a).toBe 1
expect(view.params.model).toBe model
@@ -87,7 +87,7 @@ describe "ViewRegistry", ->
getViewClass: -> TestView
model = new TestModel("hello")
node = registry.createView(model)
node = factory.createView(model)
expect(node.textContent).toBe "hello"
view = node.__spacePenView
@@ -96,17 +96,17 @@ describe "ViewRegistry", ->
describe "when the object has no .createViewClass() method", ->
it "throws an exception", ->
expect(-> registry.createView(new Object)).toThrow()
expect(-> factory.createView(new Object)).toThrow()
describe "::addViewProvider(providerSpec)", ->
it "returns a disposable that can be used to remove the provider", ->
class TestModel
class TestView
initialize: ->
disposable = registry.addViewProvider
disposable = factory.addViewProvider
modelConstructor: TestModel
viewConstructor: TestView
expect(registry.createView(new TestModel) instanceof TestView).toBe true
expect(factory.createView(new TestModel) instanceof TestView).toBe true
disposable.dispose()
expect(-> registry.createView(new TestModel)).toThrow()
expect(-> factory.createView(new TestModel)).toThrow()
+3 -3
Ver Arquivo
@@ -167,7 +167,7 @@ class Atom extends Model
# Public: A {DeserializerManager} instance
deserializers: null
# Public: A {ViewRegistry} instance
# Public: A {ViewFactory} instance
views: null
# Public: A {Workspace} instance
@@ -220,7 +220,7 @@ class Atom extends Model
Config = require './config'
KeymapManager = require './keymap-extensions'
ViewRegistry = require './view-registry'
ViewFactory = require './view-factory'
CommandRegistry = require './command-registry'
TooltipManager = require './tooltip-manager'
NotificationManager = require './notification-manager'
@@ -253,7 +253,7 @@ class Atom extends Model
@tooltips = new TooltipManager
@notifications = new NotificationManager
@commands = new CommandRegistry
@views = new ViewRegistry
@views = new ViewFactory
@packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode})
@styles = new StyleManager
document.head.appendChild(new StylesElement)
@@ -1,7 +1,7 @@
{Disposable} = require 'event-kit'
Grim = require 'grim'
# Essential: `ViewRegistry` handles the association between model and view
# Essential: `ViewFactory` handles the association between model and view
# types in Atom. We call this association a View Provider. As in, for a given
# model, this class can provide a view via {::getView}, as long as the
# model/view association was registered via {::addViewProvider}
@@ -16,7 +16,7 @@ Grim = require 'grim'
# makes [HTML 5 custom elements](http://www.html5rocks.com/en/tutorials/webcomponents/customelements/)
# an ideal tool for implementing views in Atom.
#
# You can access the `ViewRegistry` object via `atom.views`.
# You can access the `ViewFactory` object via `atom.views`.
#
# ## Examples
#
@@ -40,7 +40,7 @@ Grim = require 'grim'
# paneElement = atom.views.getView(pane)
# ```
module.exports =
class ViewRegistry
class ViewFactory
constructor: ->
@views = new WeakMap
@providers = []
+10 -10
Ver Arquivo
@@ -623,8 +623,8 @@ class Workspace extends Model
#
# * `options` {Object}
# * `item` Your panel content. It can be DOM element, a jQuery element, or
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
# latter. See {ViewRegistry::addViewProvider} for more information.
# a model with a view registered via {ViewFactory::addViewProvider}. We recommend the
# latter. See {ViewFactory::addViewProvider} for more information.
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
# (default: true)
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
@@ -642,8 +642,8 @@ class Workspace extends Model
#
# * `options` {Object}
# * `item` Your panel content. It can be DOM element, a jQuery element, or
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
# latter. See {ViewRegistry::addViewProvider} for more information.
# a model with a view registered via {ViewFactory::addViewProvider}. We recommend the
# latter. See {ViewFactory::addViewProvider} for more information.
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
# (default: true)
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
@@ -661,8 +661,8 @@ class Workspace extends Model
#
# * `options` {Object}
# * `item` Your panel content. It can be DOM element, a jQuery element, or
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
# latter. See {ViewRegistry::addViewProvider} for more information.
# a model with a view registered via {ViewFactory::addViewProvider}. We recommend the
# latter. See {ViewFactory::addViewProvider} for more information.
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
# (default: true)
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
@@ -680,8 +680,8 @@ class Workspace extends Model
#
# * `options` {Object}
# * `item` Your panel content. It can be DOM element, a jQuery element, or
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
# latter. See {ViewRegistry::addViewProvider} for more information.
# a model with a view registered via {ViewFactory::addViewProvider}. We recommend the
# latter. See {ViewFactory::addViewProvider} for more information.
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
# (default: true)
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
@@ -699,8 +699,8 @@ class Workspace extends Model
#
# * `options` {Object}
# * `item` Your panel content. It can be DOM element, a jQuery element, or
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
# latter. See {ViewRegistry::addViewProvider} for more information.
# a model with a view registered via {ViewFactory::addViewProvider}. We recommend the
# latter. See {ViewFactory::addViewProvider} for more information.
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
# (default: true)
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are