@@ -2,10 +2,12 @@ import { StatementSyntax, ValueReference } from 'glimmer-runtime';
22import { AttributeBindingReference , RootReference , applyClassNameBinding } from '../utils/references' ;
33import { DIRTY_TAG , IS_DISPATCHING_ATTRS , HAS_BLOCK } from '../component' ;
44import { assert } from 'ember-metal/debug' ;
5- import isEnabled from 'ember-metal/features' ;
6- import { meta as metaFor } from 'ember-metal/meta' ;
7- import { watchKey } from 'ember-metal/watch_key' ;
85import processArgs from '../utils/process-args' ;
6+ import { getOwner } from 'container/owner' ;
7+ import { privatize as P } from 'container/registry' ;
8+ import get from 'ember-metal/property_get' ;
9+
10+ const DEFAULT_LAYOUT = P `template:components/-default` ;
911
1012function aliasIdToElementId ( args , props ) {
1113 if ( args . named . has ( 'id' ) ) {
@@ -38,7 +40,7 @@ class ComponentStateBucket {
3840}
3941
4042class CurlyComponentManager {
41- create ( definition , args , dynamicScope ) {
43+ create ( definition , args , dynamicScope , hasBlock ) {
4244 let parentView = dynamicScope . view ;
4345
4446 let klass = definition . ComponentClass ;
@@ -48,20 +50,10 @@ class CurlyComponentManager {
4850 aliasIdToElementId ( args , props ) ;
4951
5052 props . renderer = parentView . renderer ;
51- props [ HAS_BLOCK ] = definition . isBlock ;
53+ props [ HAS_BLOCK ] = hasBlock ;
5254
5355 let component = klass . create ( props ) ;
5456
55- if ( isEnabled ( 'mandatory-setter' ) ) {
56- let meta = metaFor ( component ) ;
57- let keys = Object . keys ( props ) ;
58-
59- for ( let i = 0 ; i < keys . length ; i ++ ) {
60- // Watching a key triggers Ember to install the mandatory setter
61- watchKey ( component , keys [ i ] , meta ) ;
62- }
63- }
64-
6557 dynamicScope . view = component ;
6658 parentView . appendChild ( component ) ;
6759
@@ -105,6 +97,37 @@ class CurlyComponentManager {
10597 return bucket ;
10698 }
10799
100+ ensureCompilable ( definition , bucket , env ) {
101+ if ( definition . template ) {
102+ return definition ;
103+ }
104+
105+ let { component } = bucket ;
106+ let template ;
107+ let TemplateFactory = component . layout ;
108+ // seen the definition but not the template
109+ if ( TemplateFactory ) {
110+ if ( env . _templateCache [ TemplateFactory . id ] ) {
111+ template = env . _templateCache [ TemplateFactory . id ] ;
112+ } else {
113+ template = new TemplateFactory ( env ) ;
114+ env . _templateCache [ TemplateFactory . id ] = template ;
115+ }
116+ } else {
117+ let layoutName = component . layoutName && get ( component , 'layoutName' ) ;
118+ let owner = getOwner ( component ) ;
119+
120+ if ( layoutName ) {
121+ template = owner . lookup ( 'template:' + layoutName ) ;
122+ }
123+ if ( ! template ) {
124+ template = owner . lookup ( DEFAULT_LAYOUT ) ;
125+ }
126+ }
127+
128+ return definition . lateBound ( template ) ;
129+ }
130+
108131 getSelf ( { component } ) {
109132 return new RootReference ( component ) ;
110133 }
@@ -199,10 +222,10 @@ function elementId(vm) {
199222}
200223
201224export class CurlyComponentDefinition extends ComponentDefinition {
202- constructor ( name , ComponentClass , template , isBlock ) {
225+ constructor ( name , ComponentClass , template ) {
203226 super ( name , MANAGER , ComponentClass || Component ) ;
204227 this . template = template ;
205- this . isBlock = isBlock ;
228+ this . _cache = undefined ;
206229 }
207230
208231 compile ( builder ) {
@@ -211,4 +234,18 @@ export class CurlyComponentDefinition extends ComponentDefinition {
211234 builder . attrs . dynamic ( 'id' , elementId ) ;
212235 builder . attrs . static ( 'class' , 'ember-view' ) ;
213236 }
237+
238+ lateBound ( template ) {
239+ let definition ;
240+ if ( this . _cache ) {
241+ definition = this . _cache [ template . id ] ;
242+ } else {
243+ this . _cache = { } ;
244+ }
245+ if ( ! definition ) {
246+ definition = new CurlyComponentDefinition ( this . name , this . ComponentClass , template ) ;
247+ this . _cache [ template . id ] = definition ;
248+ }
249+ return definition ;
250+ }
214251}
0 commit comments