Allow view providers to specify a createView factory method

If present, it will be called with the model object instead of
instantiating the view constructor directly and assigning a model on it.
This gives users more flexibility when constructing views.
This commit is contained in:
Nathan Sobo
2014-09-19 15:25:35 -06:00
parent 74d772f069
commit d344adc21e
2 changed files with 22 additions and 2 deletions

View File

@@ -29,8 +29,10 @@ class ViewRegistry
object[0].__spacePenView ?= object
object[0]
else if provider = @findProvider(object)
element = new provider.viewConstructor
element.setModel(object)
element = provider.createView?(object)
unless element?
element = new provider.viewConstructor
element.setModel(object)
element
else if viewConstructor = object?.getViewClass?()
view = new viewConstructor(object)