Skip to content

Commit

Permalink
better svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinJoyce committed Oct 25, 2019
1 parent f6fda97 commit b7123ac
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 83 deletions.
68 changes: 64 additions & 4 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { privatize as P } from '@ember/-internals/container';
import { ENV } from '@ember/-internals/environment';
import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner';
import { lookupPartial, OwnedTemplateMeta } from '@ember/-internals/views';
import { OwnedTemplateMeta } from '@ember/-internals/views';
import {
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE,
EMBER_MODULE_UNIFICATION,
} from '@ember/canary-features';
import { isTemplateOnlyComponent } from '@ember/component/template-only';
import { assert } from '@ember/debug';
import { assert, deprecate } from '@ember/debug';
import { PARTIALS } from '@ember/deprecated-features';
import EmberError from '@ember/error';
import { _instrumentStart } from '@ember/instrumentation';
import {
ComponentDefinition,
Expand Down Expand Up @@ -176,6 +178,60 @@ function lookupComponent(owner: Owner, name: string, options: LookupOptions): Op
return lookupComponentPair(owner, name);
}

let lookupPartial: { templateName: string; owner: Owner } | any;

if (PARTIALS) {
lookupPartial = function(templateName: string, owner: Owner) {
deprecate(
`The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`,
false,
{
id: 'ember-views.partial',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial',
}
);

if (templateName === null) {
return;
}

let template = templateFor(owner, parseUnderscoredName(templateName), templateName);

assert(`Unable to find partial with name "${templateName}"`, Boolean(template));

return template;
};

function templateFor(owner: any, underscored: string, name: string) {
if (PARTIALS) {
if (!name) {
return;
}
assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1);

if (!owner) {
throw new EmberError(
'Container was not found when looking up a views template. ' +
'This is most likely due to manually instantiating an Ember.View. ' +
'See: http://git.io/EKPpnA'
);
}

return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`);
}
}

function parseUnderscoredName(templateName: string) {
let nameParts = templateName.split('/');
let lastPart = nameParts[nameParts.length - 1];

nameParts[nameParts.length - 1] = `_${lastPart}`;

return nameParts.join('/');
}
}

interface IBuiltInHelpers {
[name: string]: Helper | undefined;
}
Expand Down Expand Up @@ -306,8 +362,12 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
* Called by CompileTimeLookup to lookup partial
*/
lookupPartial(name: string, meta: OwnedTemplateMeta): Option<number> {
let partial = this._lookupPartial(name, meta);
return this.handle(partial);
if (PARTIALS) {
let partial = this._lookupPartial(name, meta);
return this.handle(partial);
} else {
return null;
}
}

// end CompileTimeLookup
Expand Down
4 changes: 0 additions & 4 deletions packages/@ember/-internals/views/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export function isSimpleClick(event: Event): boolean;

export function constructStyleDeprecationMessage(affectedStyle: any): string;

export function hasPartial(name: string, owner: any): boolean;

export function lookupPartial(templateName: string, owner: Owner): TemplateFactory;

export function getViewId(view: any): string;

export const MUTABLE_CELL: string;
Expand Down
1 change: 0 additions & 1 deletion packages/@ember/-internals/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ export { default as ViewStateSupport } from './lib/mixins/view_state_support';
export { default as ViewMixin } from './lib/mixins/view_support';
export { default as ActionSupport } from './lib/mixins/action_support';
export { MUTABLE_CELL } from './lib/compat/attrs';
export { default as lookupPartial, hasPartial } from './lib/system/lookup_partial';
export { default as ActionManager } from './lib/system/action_manager';
74 changes: 0 additions & 74 deletions packages/@ember/-internals/views/lib/system/lookup_partial.js

This file was deleted.

0 comments on commit b7123ac

Please sign in to comment.