Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Expriment] Lazy rexports + pay as you go #11576

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<body>
<script>
function writeTime(time) {
var div = document.createElement('div');
div.textContent = time + 'ms';
document.body.appendChild(div);
}
var jqueryStart = new Date();
</script>
<script src="dist/jquery/jquery.js"></script>
<script>

writeTime("jquery:" + (new Date() - jqueryStart));
var emberStart = new Date();
</script>
<cript src="ember.min.js"></cript>
<script src="dist/ember.min.js"></script> <script>
writeTime("ember:" + (new Date() - emberStart));
</script>
</body>
6 changes: 2 additions & 4 deletions packages/container/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ if (Ember.ENV && typeof Ember.ENV.MODEL_FACTORY_INJECTIONS !== 'undefined') {
Ember.MODEL_FACTORY_INJECTIONS = !!Ember.ENV.MODEL_FACTORY_INJECTIONS;
}

import Registry from 'container/registry';
import Container from 'container/container';

export { Registry, Container };
export { default as Registry } from 'container/registry';
export { default as Container } from 'container/container';
18 changes: 7 additions & 11 deletions packages/ember-application/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import Ember from 'ember-metal/core';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';

/**
@module ember
@submodule ember-application
*/

import DefaultResolver from 'ember-application/system/resolver';
import {
Resolver
} from 'ember-application/system/resolver';
import Application from 'ember-application/system/application';
Ember.onLoad('Ember.Application', function() {
Ember.__loader.require('ember-application/ext/controller');
});

Ember.Application = Application;
Ember.Resolver = Resolver;
Ember.DefaultResolver = DefaultResolver;
var reexport = Ember.__reexport;


runLoadHooks('Ember.Application', Application);
reexport('ember-application/system/application', 'Application');
reexport('ember-application/system/resolver', ['Resolver']);
reexport('ember-application/system/resolver', 'DefaultResolver');
108 changes: 51 additions & 57 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
@submodule ember-application
*/
import DAG from 'dag-map';
import Registry from 'container/registry';

import Ember from 'ember-metal'; // Ember.libraries, LOG_VERSION, Namespace, BOOTED
import { assert, deprecate, debug } from 'ember-metal/debug';
Expand All @@ -13,36 +12,14 @@ import { set } from 'ember-metal/property_set';
import EmptyObject from 'ember-metal/empty_object';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';
import Namespace from 'ember-runtime/system/namespace';
import DefaultResolver from 'ember-application/system/resolver';
import run from 'ember-metal/run_loop';
import { canInvoke } from 'ember-metal/utils';
import Controller from 'ember-runtime/controllers/controller';
import Renderer from 'ember-metal-views/renderer';
import DOMHelper from 'ember-htmlbars/system/dom-helper';
import SelectView from 'ember-views/views/select';
import { OutletView } from 'ember-routing-views/views/outlet';
import EmberView from 'ember-views/views/view';
import EventDispatcher from 'ember-views/system/event_dispatcher';
import jQuery from 'ember-views/system/jquery';
import Route from 'ember-routing/system/route';
import Router from 'ember-routing/system/router';
import HashLocation from 'ember-routing/location/hash_location';
import HistoryLocation from 'ember-routing/location/history_location';
import AutoLocation from 'ember-routing/location/auto_location';
import NoneLocation from 'ember-routing/location/none_location';
import BucketCache from 'ember-routing/system/cache';
import ApplicationInstance from 'ember-application/system/application-instance';
import TextField from 'ember-views/views/text_field';
import TextArea from 'ember-views/views/text_area';
import Checkbox from 'ember-views/views/checkbox';
import LegacyEachView from 'ember-views/views/legacy_each_view';
import LinkToComponent from 'ember-routing-views/components/link-to';
import RoutingService from 'ember-routing/services/routing';
import ContainerDebugAdapter from 'ember-extension-support/container_debug_adapter';
import { _loaded } from 'ember-runtime/system/lazy_load';
import RegistryProxy, { buildFakeRegistryWithDeprecations } from 'ember-runtime/mixins/registry_proxy';

import environment from 'ember-metal/environment';

function require(path, key = 'default') {
return Ember.__loader.require(path)[key];
}

function props(obj) {
var properties = [];

Expand Down Expand Up @@ -308,8 +285,9 @@ var Application = Namespace.extend(RegistryProxy, {
init() {
this._super(...arguments);

this._run = require('ember-metal/run_loop');
if (!this.$) {
this.$ = jQuery;
this.$ = require('ember-views/system/jquery');
}

this.buildRegistry();
Expand All @@ -318,9 +296,10 @@ var Application = Namespace.extend(RegistryProxy, {
logLibraryVersions();

// Start off the number of deferrals at 1. This will be
// decremented by the Application's own `initialize` method.
// decremented by the Application's own `unitialize` method.
this._readinessDeferrals = 1;

var Router = require('ember-routing/system/router');
if (isEnabled('ember-application-visit')) {
if (this.autoboot) {
// Create subclass of Ember.Router for this Application instance.
Expand Down Expand Up @@ -359,6 +338,7 @@ var Application = Namespace.extend(RegistryProxy, {
@return {Ember.Container} the configured container
*/
buildInstance() {
var ApplicationInstance = require('ember-application/system/application-instance');
return ApplicationInstance.create({
application: this
});
Expand All @@ -367,6 +347,7 @@ var Application = Namespace.extend(RegistryProxy, {
buildDefaultInstance() {
var instance = this.buildInstance();

var EmberView = require('ember-views/views/view');
// For the default instance only, set the view registry to the global
// Ember.View.views hash for backwards-compatibility.
EmberView.views = instance.lookup('-view-registry:main');
Expand Down Expand Up @@ -398,9 +379,9 @@ var Application = Namespace.extend(RegistryProxy, {
*/
waitForDOMReady() {
if (!this.$ || this.$.isReady) {
run.schedule('actions', this, 'domReady');
this._run.schedule('actions', this, 'domReady');
} else {
this.$().ready(run.bind(this, 'domReady'));
this.$().ready(this._run.bind(this, 'domReady'));
}
},

Expand Down Expand Up @@ -450,7 +431,7 @@ var Application = Namespace.extend(RegistryProxy, {
this._readinessDeferrals--;

if (this._readinessDeferrals === 0) {
run.once(this, this.didBecomeReady);
this._run.once(this, this.didBecomeReady);
}
},

Expand Down Expand Up @@ -576,6 +557,7 @@ var Application = Namespace.extend(RegistryProxy, {
this._readinessDeferrals = 1;
this._bootPromise = null;
this._bootResolver = null;
var run = this._run;

function handleReset() {
run(instance, 'destroy');
Expand Down Expand Up @@ -977,6 +959,7 @@ Application.reopenClass({
@public
*/
buildRegistry(namespace) {
var Registry = require('container/registry');
var registry = new Registry();

registry.set = set;
Expand All @@ -991,51 +974,57 @@ Application.reopenClass({

registry.register('application:main', namespace, { instantiate: false });

registry.register('controller:basic', Controller, { instantiate: false });
registry.register('controller:basic', require('ember-runtime/controllers/controller'), { instantiate: false });
registry.register('controller:object', require('ember-runtime/controllers/object_controller'), { instantiate: false });
registry.register('controller:array', require('ember-runtime/controllers/array_controller'), { instantiate: false });

registry.register('renderer:-dom', { create() { return new Renderer(new DOMHelper()); } });
registry.register('renderer:-dom', {
create() {
var Renderer = require('ember-metal-views/renderer');
var DOMHelper = require('ember-htmlbars/system/dom-helper');

return new Renderer(new DOMHelper());
}
});

registry.injection('view', 'renderer', 'renderer:-dom');
if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) {
registry.register('view:select', SelectView);
}
registry.register('view:-outlet', OutletView);
registry.register('view:select', require('ember-views/views/select'));
registry.register('view:-outlet', require('ember-routing-views/views/outlet', 'OutletView'));

registry.register('-view-registry:main', { create() { return {}; } });

registry.injection('view', '_viewRegistry', '-view-registry:main');

registry.register('view:toplevel', EmberView.extend());
registry.register('view:toplevel', require('ember-views/views/view'));

registry.register('route:basic', Route, { instantiate: false });
registry.register('event_dispatcher:main', EventDispatcher);
registry.register('route:basic', require('ember-routing/system/route'), { instantiate: false });
registry.register('event_dispatcher:main', require('ember-views/system/event_dispatcher'));

registry.injection('router:main', 'namespace', 'application:main');
registry.injection('view:-outlet', 'namespace', 'application:main');

registry.register('location:auto', AutoLocation);
registry.register('location:hash', HashLocation);
registry.register('location:history', HistoryLocation);
registry.register('location:none', NoneLocation);
registry.register('location:auto', require('ember-routing/location/auto_location'));
registry.register('location:hash', require('ember-routing/location/hash_location'));
registry.register('location:history', require('ember-routing/location/history_location'));
registry.register('location:none', require('ember-routing/location/none_location'));

registry.injection('controller', 'target', 'router:main');
registry.injection('controller', 'namespace', 'application:main');

registry.register('-bucket-cache:main', BucketCache);
registry.register('-bucket-cache:main', require('ember-routing/system/cache'));
registry.injection('router', '_bucketCache', '-bucket-cache:main');
registry.injection('route', '_bucketCache', '-bucket-cache:main');
registry.injection('controller', '_bucketCache', '-bucket-cache:main');

registry.injection('route', 'router', 'router:main');

registry.register('component:-text-field', TextField);
registry.register('component:-text-area', TextArea);
registry.register('component:-checkbox', Checkbox);
registry.register('view:-legacy-each', LegacyEachView);
registry.register('component:link-to', LinkToComponent);
registry.register('component:-text-field', require('ember-views/views/text_field'));
registry.register('component:-text-area', require('ember-views/views/text_area'));
registry.register('component:-checkbox', require('ember-views/views/checkbox'));
registry.register('view:-legacy-each', require('ember-views/views/legacy_each_view'));
registry.register('component:-link-to', require('ember-routing-views/views/link'));

// Register the routing service...
registry.register('service:-routing', RoutingService);
registry.register('service:-routing', require('ember-routing/services/routing'));
// Then inject the app router into it
registry.injection('service:-routing', 'router', 'router:main');

Expand All @@ -1045,7 +1034,7 @@ Application.reopenClass({
registry.injection('data-adapter:main', 'containerDebugAdapter', 'container-debug-adapter:main');
// Custom resolver authors may want to register their own ContainerDebugAdapter with this key

registry.register('container-debug-adapter:main', ContainerDebugAdapter);
registry.register('container-debug-adapter:main', require('ember-extension-support/container_debug_adapter'));

return registry;
}
Expand All @@ -1068,7 +1057,9 @@ Application.reopenClass({
@return {*} the resolved value for a given lookup
*/
function resolverFor(namespace) {
var ResolverClass = namespace.get('Resolver') || DefaultResolver;
Ember.deprecate('Application.resolver is deprecated in favor of Application.Resolver', !namespace.get('resolver'));

var ResolverClass = namespace.get('resolver') || namespace.get('Resolver') || require('ember-application/system/resolver');
var resolver = ResolverClass.create({
namespace: namespace
});
Expand Down Expand Up @@ -1109,7 +1100,7 @@ function registerLibraries() {
librariesRegistered = true;

if (environment.hasDOM) {
Ember.libraries.registerCoreLibrary('jQuery', jQuery().jquery);
Ember.libraries.registerCoreLibrary('jQuery', require('ember-views/system/jquery'));
}
}
}
Expand Down Expand Up @@ -1147,6 +1138,7 @@ function buildInitializerMethod(bucketName, humanName) {
attrs[bucketName] = Object.create(this[bucketName]);
this.reopenClass(attrs);
}
var canInvoke = require('ember-metal/utils', 'canInvoke');

assert('The ' + humanName + ' \'' + initializer.name + '\' has already been registered', !this[bucketName][initializer.name]);
assert('An ' + humanName + ' cannot be registered without an initialize function', canInvoke(initializer, 'initialize'));
Expand All @@ -1157,3 +1149,5 @@ function buildInitializerMethod(bucketName, humanName) {
}

export default Application;

runLoadHooks('Ember.Application', Application);
8 changes: 4 additions & 4 deletions packages/ember-extension-support/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import Ember from 'ember-metal/core';
import DataAdapter from 'ember-extension-support/data_adapter';
import ContainerDebugAdapter from 'ember-extension-support/container_debug_adapter';

Ember.DataAdapter = DataAdapter;
Ember.ContainerDebugAdapter = ContainerDebugAdapter;
var reexport = Ember.__reexport;

reexport('ember-extension-support/data_adapter', 'DataAdapter');
reexport('ember-extension-support/container_debug_adapter', 'ContainerDebugAdapter');
22 changes: 13 additions & 9 deletions packages/ember-htmlbars/lib/system/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import Ember from 'ember-metal/core';
import ComponentLookup from 'ember-views/component_lookup';
import jQuery from 'ember-views/system/jquery';
import EmberError from 'ember-metal/error';
import { onLoad } from 'ember-runtime/system/lazy_load';
import htmlbarsCompile from 'ember-template-compiler/system/compile';
import environment from 'ember-metal/environment';

function require(path, name = 'default') {
return Ember.__loader.require(path)[name];
}

/**
@module ember
Expand All @@ -37,6 +36,7 @@ import environment from 'ember-metal/environment';
function bootstrap(ctx) {
var selectors = 'script[type="text/x-handlebars"], script[type="text/x-raw-handlebars"]';

var jQuery = require('ember-views/system/jquery')(document);
jQuery(selectors, ctx)
.each(function() {
// Get a reference to the script tag
Expand All @@ -52,11 +52,13 @@ function bootstrap(ctx) {
compile = jQuery.proxy(Handlebars.compile, Handlebars);
template = compile(script.html());
} else {
var htmlbarsCompile = require('ember-template-compiler/system/compile');
template = htmlbarsCompile(script.html(), {
moduleName: templateName
});
}

var EmberError = require('ember-metal/error');
// Check if template of same name already exists
if (Ember.TEMPLATES[templateName] !== undefined) {
throw new EmberError('Template named "' + templateName + '" already exists.');
Expand All @@ -71,11 +73,11 @@ function bootstrap(ctx) {
}

function _bootstrap() {
bootstrap(jQuery(document));
bootstrap(require('ember-views/system/jquery')(document));
}

function registerComponentLookup(app) {
app.register('component-lookup:main', ComponentLookup);
app.registry.register('component-lookup:main', require('ember-views/component_lookupComponentLookup'));
}

/*
Expand All @@ -90,12 +92,14 @@ function registerComponentLookup(app) {
*/

onLoad('Ember.Application', function(Application) {
Application.initializer({
var environment = require('ember-metal/environment');

Ember.Application.initializer({
name: 'domTemplates',
initialize: environment.hasDOM ? _bootstrap : function() { }
});

Application.instanceInitializer({
Ember.Application.instanceInitializer({
name: 'registerComponentLookup',
initialize: registerComponentLookup
});
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-metal-views/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import Renderer from 'ember-metal-views/renderer';
export { Renderer };
export { Renderer } from 'ember-metal-views/renderer';
Loading