Skip to content

Commit b7123ac

Browse files
committed
better svelte
1 parent f6fda97 commit b7123ac

File tree

4 files changed

+64
-83
lines changed

4 files changed

+64
-83
lines changed

packages/@ember/-internals/glimmer/lib/resolver.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { privatize as P } from '@ember/-internals/container';
22
import { ENV } from '@ember/-internals/environment';
33
import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner';
4-
import { lookupPartial, OwnedTemplateMeta } from '@ember/-internals/views';
4+
import { OwnedTemplateMeta } from '@ember/-internals/views';
55
import {
66
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE,
77
EMBER_MODULE_UNIFICATION,
88
} from '@ember/canary-features';
99
import { isTemplateOnlyComponent } from '@ember/component/template-only';
10-
import { assert } from '@ember/debug';
10+
import { assert, deprecate } from '@ember/debug';
11+
import { PARTIALS } from '@ember/deprecated-features';
12+
import EmberError from '@ember/error';
1113
import { _instrumentStart } from '@ember/instrumentation';
1214
import {
1315
ComponentDefinition,
@@ -176,6 +178,60 @@ function lookupComponent(owner: Owner, name: string, options: LookupOptions): Op
176178
return lookupComponentPair(owner, name);
177179
}
178180

181+
let lookupPartial: { templateName: string; owner: Owner } | any;
182+
183+
if (PARTIALS) {
184+
lookupPartial = function(templateName: string, owner: Owner) {
185+
deprecate(
186+
`The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`,
187+
false,
188+
{
189+
id: 'ember-views.partial',
190+
until: '4.0.0',
191+
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial',
192+
}
193+
);
194+
195+
if (templateName === null) {
196+
return;
197+
}
198+
199+
let template = templateFor(owner, parseUnderscoredName(templateName), templateName);
200+
201+
assert(`Unable to find partial with name "${templateName}"`, Boolean(template));
202+
203+
return template;
204+
};
205+
206+
function templateFor(owner: any, underscored: string, name: string) {
207+
if (PARTIALS) {
208+
if (!name) {
209+
return;
210+
}
211+
assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1);
212+
213+
if (!owner) {
214+
throw new EmberError(
215+
'Container was not found when looking up a views template. ' +
216+
'This is most likely due to manually instantiating an Ember.View. ' +
217+
'See: http://git.io/EKPpnA'
218+
);
219+
}
220+
221+
return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`);
222+
}
223+
}
224+
225+
function parseUnderscoredName(templateName: string) {
226+
let nameParts = templateName.split('/');
227+
let lastPart = nameParts[nameParts.length - 1];
228+
229+
nameParts[nameParts.length - 1] = `_${lastPart}`;
230+
231+
return nameParts.join('/');
232+
}
233+
}
234+
179235
interface IBuiltInHelpers {
180236
[name: string]: Helper | undefined;
181237
}
@@ -306,8 +362,12 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
306362
* Called by CompileTimeLookup to lookup partial
307363
*/
308364
lookupPartial(name: string, meta: OwnedTemplateMeta): Option<number> {
309-
let partial = this._lookupPartial(name, meta);
310-
return this.handle(partial);
365+
if (PARTIALS) {
366+
let partial = this._lookupPartial(name, meta);
367+
return this.handle(partial);
368+
} else {
369+
return null;
370+
}
311371
}
312372

313373
// end CompileTimeLookup

packages/@ember/-internals/views/index.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export function isSimpleClick(event: Event): boolean;
3535

3636
export function constructStyleDeprecationMessage(affectedStyle: any): string;
3737

38-
export function hasPartial(name: string, owner: any): boolean;
39-
40-
export function lookupPartial(templateName: string, owner: Owner): TemplateFactory;
41-
4238
export function getViewId(view: any): string;
4339

4440
export const MUTABLE_CELL: string;

packages/@ember/-internals/views/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ export { default as ViewStateSupport } from './lib/mixins/view_state_support';
2626
export { default as ViewMixin } from './lib/mixins/view_support';
2727
export { default as ActionSupport } from './lib/mixins/action_support';
2828
export { MUTABLE_CELL } from './lib/compat/attrs';
29-
export { default as lookupPartial, hasPartial } from './lib/system/lookup_partial';
3029
export { default as ActionManager } from './lib/system/action_manager';

packages/@ember/-internals/views/lib/system/lookup_partial.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)