dist/ember.prod.js in ember-source-1.2.0.beta.2 vs dist/ember.prod.js in ember-source-1.2.0.beta.3

- old
+ new

@@ -6,11 +6,11 @@ // License: Licensed under MIT license // See https://raw.github.com/emberjs/ember.js/master/LICENSE // ========================================================================== - // Version: 1.2.0-beta.2 + // Version: 1.2.0-beta.3 (function() { var define, requireModule; (function() { @@ -71,11 +71,11 @@ The core Runtime framework is based on the jQuery API with a number of performance optimizations. @class Ember @static - @version 1.2.0-beta.2 + @version 1.2.0-beta.3 */ if ('undefined' === typeof Ember) { // Create core object. Make it act like an instance of Ember.Namespace so that // objects assigned to it are given a sane string representation. @@ -98,14 +98,14 @@ /** @property VERSION @type String - @default '1.2.0-beta.2' + @default '1.2.0-beta.3' @final */ -Ember.VERSION = '1.2.0-beta.2'; +Ember.VERSION = '1.2.0-beta.3'; /** Standard environmental variables. You can define these in a global `ENV` variable before loading Ember to control various configuration settings. @@ -349,11 +349,11 @@ @method create @for Ember */ Ember.create = Object.create; -// IE8 has Object.create but it couldn't treat property descripters. +// IE8 has Object.create but it couldn't treat property descriptors. if (Ember.create) { if (Ember.create({a: 1}, {a: {value: 2}}).a !== 2) { Ember.create = null; } } @@ -15604,11 +15604,10 @@ Example: ```javascript App.Person = Ember.Object.extend({ init: function() { - this._super(); alert('Name is ' + this.get('name')); } }); var steve = App.Person.create({ @@ -17222,11 +17221,11 @@ /** Creates an `Ember.NativeArray` from an Array like object. Does not modify the original object. Ember.A is not needed if `Ember.EXTEND_PROTOTYPES` is `true` (the default value). However, it is recommended that you use Ember.A when creating addons for - ember or when you can not garentee that `Ember.EXTEND_PROTOTYPES` + ember or when you can not guarantee that `Ember.EXTEND_PROTOTYPES` will be `true`. Example ```js @@ -20330,43 +20329,32 @@ // /** The name of the template to lookup if no template is provided. - `Ember.View` will look for a template with this name in this view's - `templates` object. By default, this will be a global object - shared in `Ember.TEMPLATES`. + By default `Ember.View` will lookup a template with this name in + `Ember.TEMPLATES` (a shared global object). @property templateName @type String @default null */ templateName: null, /** The name of the layout to lookup if no layout is provided. - `Ember.View` will look for a template with this name in this view's - `templates` object. By default, this will be a global object - shared in `Ember.TEMPLATES`. + By default `Ember.View` will lookup a template with this name in + `Ember.TEMPLATES` (a shared global object). @property layoutName @type String @default null */ layoutName: null, /** - The hash in which to look for `templateName`. - - @property templates - @type Ember.Object - @default Ember.TEMPLATES - */ - templates: Ember.TEMPLATES, - - /** The template used to render the view. This should be a function that accepts an optional context parameter and returns a string of HTML that will be inserted into the DOM relative to its parent view. In general, you should set the `templateName` property instead of setting @@ -29210,11 +29198,11 @@ // A better strategy would properly resolve /posts/:id/new and /posts/edit/:id function sortSolutions(states) { return states.sort(function(a, b) { if (a.types.stars !== b.types.stars) { return a.types.stars - b.types.stars; } if (a.types.dynamics !== b.types.dynamics) { return a.types.dynamics - b.types.dynamics; } - if (a.types.statics !== b.types.statics) { return a.types.statics - b.types.statics; } + if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; } return 0; }); } @@ -29576,12 +29564,12 @@ (function() { define("router", - ["route-recognizer","rsvp"], - function(RouteRecognizer, RSVP) { + ["route-recognizer","rsvp","exports"], + function(__dependency1__, __dependency2__, __exports__) { "use strict"; /** @private This file references several internal structures: @@ -29597,10 +29585,12 @@ * `{String} name`: the name of a handler * `{Object} handler`: a handler object * `{Object} context`: the active context for the handler */ + var RouteRecognizer = __dependency1__; + var RSVP = __dependency2__; var slice = Array.prototype.slice; @@ -29751,10 +29741,11 @@ } // TODO: separate into module? Router.Transition = Transition; + __exports__['default'] = Router; /** Promise reject reasons passed to promise rejection handlers for failed transitions. @@ -30106,11 +30097,11 @@ (paramName && activeTransition.providedModels[handlerName]); } } function isParam(object) { - return (typeof object === "string" || object instanceof String || !isNaN(object)); + return (typeof object === "string" || object instanceof String || typeof object === "number" || object instanceof Number); } /** @@ -30279,11 +30270,11 @@ if (results) { // Make sure this route is actually accessible by URL. for (i = 0, len = results.length; i < len; ++i) { - if (router.getHandler(results[i].handler).inaccessiblyByURL) { + if (router.getHandler(results[i].handler).inaccessibleByURL) { results = null; break; } } } @@ -30646,19 +30637,12 @@ function transitionSuccess() { checkAbort(transition); try { - log(router, transition.sequence, "Validation succeeded, finalizing transition;"); + finalizeTransition(transition, handlerInfos); - // Don't overwrite contexts / update URL if this was a noop transition. - if (!currentHandlerInfos || !currentHandlerInfos.length || - !router.recognizer.hasRoute(currentHandlerInfos[currentHandlerInfos.length - 1].name) || - currentHandlerInfos.length !== matchPointResults.matchPoint) { - finalizeTransition(transition, handlerInfos); - } - // currentHandlerInfos was updated in finalizeTransition trigger(router, router.currentHandlerInfos, true, ['didTransition']); if (router.didTransition) { router.didTransition(handlerInfos); @@ -30738,10 +30722,12 @@ Updates the URL (if necessary) and calls `setupContexts` to update the router's array of `currentHandlerInfos`. */ function finalizeTransition(transition, handlerInfos) { + log(transition.router, transition.sequence, "Validation succeeded, finalizing transition;"); + var router = transition.router, seq = transition.sequence, handlerName = handlerInfos[handlerInfos.length - 1].name, urlMethod = transition.urlMethod, i; @@ -30753,11 +30739,11 @@ if (handlerInfo.isDynamic) { var providedModel = providedModels.pop(); objects.unshift(isParam(providedModel) ? providedModel.toString() : handlerInfo.context); } - if (handlerInfo.handler.inaccessiblyByURL) { + if (handlerInfo.handler.inaccessibleByURL) { urlMethod = null; } } var newQueryParams = {}; @@ -30840,11 +30826,11 @@ return result; } function handleError(reason) { - if (reason instanceof Router.TransitionAborted) { + if (reason instanceof Router.TransitionAborted || transition.isAborted) { // if the transition was aborted and *no additional* error was thrown, // reject with the Router.TransitionAborted instance return RSVP.reject(reason); } @@ -31027,13 +31013,10 @@ } else { object[name] = model; } return object; } - - - return Router; }); })(); @@ -31064,40 +31047,29 @@ options.path = "/" + name; } if (callback) { var dsl = new DSL(name); - dsl.route('loading'); - dsl.route('error', { path: "/_unused_dummy_error_path/:error" }); + route(dsl, 'loading'); + route(dsl, 'error', { path: "/_unused_dummy_error_path_route_" + name + "/:error" }); callback.call(dsl); this.push(options.path, name, dsl.generate(), options.queryParams); } else { this.push(options.path, name, null, options.queryParams); } + }, push: function(url, name, callback, queryParams) { var parts = name.split('.'); if (url === "" || url === "/" || parts[parts.length-1] === "index") { this.explicitIndex = true; } this.matches.push([url, name, callback, queryParams]); }, route: function(name, options) { - - - options = options || {}; - - if (typeof options.path !== 'string') { - options.path = "/" + name; - } - - if (this.parent && this.parent !== 'application') { - name = this.parent + "." + name; - } - - this.push(options.path, name, null, options.queryParams); + route(this, name, options); }, generate: function() { var dslMatches = this.matches; @@ -31112,10 +31084,26 @@ } }; } }; +function route(dsl, name, options) { + + + options = options || {}; + + if (typeof options.path !== 'string') { + options.path = "/" + name; + } + + if (dsl.parent && dsl.parent !== 'application') { + name = dsl.parent + "." + name; + } + + dsl.push(options.path, name, null, options.queryParams); +} + DSL.map = function(callback) { var dsl = new DSL(); callback.call(dsl); return dsl; }; @@ -31197,11 +31185,11 @@ /** @module ember @submodule ember-routing */ -var Router = requireModule("router"); +var Router = requireModule("router")['default']; var get = Ember.get, set = Ember.set; var defineProperty = Ember.defineProperty; var DefaultView = Ember._MetamorphView; /** @@ -31472,21 +31460,139 @@ } this._loadingStateTimer = null; } }); +/** + @private + + Helper function for iterating root-ward, starting + from (but not including) the provided `originRoute`. + + Returns true if the last callback fired requested + to bubble upward. + */ +function forEachRouteAbove(originRoute, transition, callback) { + var handlerInfos = transition.handlerInfos, + originRouteFound = false; + + for (var i = handlerInfos.length - 1; i >= 0; --i) { + var handlerInfo = handlerInfos[i], + route = handlerInfo.handler; + + if (!originRouteFound) { + if (originRoute === route) { + originRouteFound = true; + } + continue; + } + + if (callback(route, handlerInfos[i + 1].handler) !== true) { + return false; + } + } + return true; +} + +// These get invoked when an action bubbles above ApplicationRoute +// and are not meant to be overridable. +var defaultActionHandlers = { + + willResolveModel: function(transition, originRoute) { + originRoute.router._scheduleLoadingEvent(transition, originRoute); + }, + + error: function(error, transition, originRoute) { + + + // Attempt to find an appropriate error substate to enter. + var router = originRoute.router; + + var tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { + var childErrorRouteName = findChildRouteName(route, childRoute, 'error'); + if (childErrorRouteName) { + router.intermediateTransitionTo(childErrorRouteName, error); + return; + } + return true; + }); + + if (tryTopLevel) { + // Check for top-level error state to enter. + if (routeHasBeenDefined(originRoute.router, 'application_error')) { + router.intermediateTransitionTo('application_error', error); + return; + } + } else { + // Don't fire an assertion if we found an error substate. + return; + } + + + Ember.Logger.assert(false, 'Error while loading route: ' + Ember.inspect(error)); + }, + + loading: function(transition, originRoute) { + + + // Attempt to find an appropriate loading substate to enter. + var router = originRoute.router; + + var tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { + var childLoadingRouteName = findChildRouteName(route, childRoute, 'loading'); + + if (childLoadingRouteName) { + router.intermediateTransitionTo(childLoadingRouteName); + return; + } + + // Don't bubble above pivot route. + if (transition.pivotHandler !== route) { + return true; + } + }); + + if (tryTopLevel) { + // Check for top-level loading state to enter. + if (routeHasBeenDefined(originRoute.router, 'application_loading')) { + router.intermediateTransitionTo('application_loading'); + return; + } + } + + } +}; + +function findChildRouteName(parentRoute, originatingChildRoute, name) { + var router = parentRoute.router, + childName, + targetChildRouteName = originatingChildRoute.routeName.split('.').pop(), + namespace = parentRoute.routeName === 'application' ? '' : parentRoute.routeName + '.'; + + childName = namespace + name; + if (routeHasBeenDefined(router, childName)) { + return childName; + } +} + +function routeHasBeenDefined(router, name) { + var container = router.container; + return router.hasRoute(name) && + (container.has('template:' + name) || container.has('route:' + name)); +} + function triggerEvent(handlerInfos, ignoreFailure, args) { var name = args.shift(); if (!handlerInfos) { if (ignoreFailure) { return; } - throw new Ember.Error("Could not trigger event '" + name + "'. There are no active handlers"); + throw new Ember.Error("Can't trigger action '" + name + "' because your app hasn't finished transitioning into its first route. To trigger an action on destination routes during a transition, you can call `.send()` on the `Transition` object passed to the `model/beforeModel/afterModel` hooks."); } var eventWasHandled = false; - for (var i=handlerInfos.length-1; i>=0; i--) { + for (var i = handlerInfos.length - 1; i >= 0; i--) { var handlerInfo = handlerInfos[i], handler = handlerInfo.handler; if (handler._actions && handler._actions[name]) { if (handler._actions[name].apply(handler, args) === true) { @@ -31495,18 +31601,31 @@ return; } } } + if (defaultActionHandlers[name]) { + defaultActionHandlers[name].apply(null, args); + return; + } + if (!eventWasHandled && !ignoreFailure) { - throw new Ember.Error("Nothing handled the action '" + name + "'. If you did handle the action, this error can be caused by returning true from an action handler, causing the action to bubble."); + throw new Ember.Error("Nothing handled the action '" + name + "'."); } } function updatePaths(router) { - var appController = router.container.lookup('controller:application'), - infos = router.router.currentHandlerInfos, + var appController = router.container.lookup('controller:application'); + + if (!appController) { + // appController might not exist when top-level loading/error + // substates have been entered since ApplicationRoute hasn't + // actually been entered at that point. + return; + } + + var infos = router.router.currentHandlerInfos, path = Ember.Router._routePath(infos); if (!('currentPath' in appController)) { defineProperty(appController, 'currentPath'); } @@ -31617,52 +31736,11 @@ classify = Ember.String.classify, fmt = Ember.String.fmt, a_forEach = Ember.EnumerableUtils.forEach, a_replace = Ember.EnumerableUtils.replace; -var defaultActionHandlers = { - willResolveModel: function(transition, originRoute) { - this.router._scheduleLoadingEvent(transition, originRoute); - }, - - error: function(error, transition, originRoute) { - - if (this !== originRoute) { - var childErrorRouteName = findChildRouteName(this, 'error'); - if (childErrorRouteName) { - this.intermediateTransitionTo(childErrorRouteName, error); - return; - } - } - - - if (this.routeName === 'application') { - Ember.Logger.assert(false, 'Error while loading route: ' + Ember.inspect(error)); - } - - return true; - }, - - loading: function(transition, originRoute) { - - if (this === originRoute) { - // This is the route with the error; just bubble - // so that the parent route can look up its child loading route. - return true; - } - - var childLoadingRouteName = findChildRouteName(this, 'loading'); - if (childLoadingRouteName) { - this.intermediateTransitionTo(childLoadingRouteName); - } else if (transition.pivotHandler !== this) { - return true; - } - - } -}; - /** The `Ember.Route` class is used to define individual routes. Refer to the [routing guide](http://emberjs.com/guides/routing/) for documentation. @class Route @@ -31903,19 +31981,17 @@ @type Hash @default null */ actions: null, - _actions: defaultActionHandlers, - /** @deprecated Please use `actions` instead. @method events */ - events: defaultActionHandlers, + events: null, mergedProperties: ['events'], /** This hook is executed when the router completely exits this route. It is @@ -31924,12 +32000,12 @@ @method deactivate */ deactivate: Ember.K, /** - This hook is executed when the router enters the route for the first time. - It is not executed when the model for the route changes. + This hook is executed when the router enters the route. It is not executed + when the model for the route changes. @method activate */ activate: Ember.K, @@ -32451,11 +32527,11 @@ For the `post` route, a controller named `App.PostController` would be used if it is defined. If it is not defined, an `Ember.ObjectController` instance would be used. Example - + ```js App.PostRoute = Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); } @@ -32877,20 +32953,9 @@ function generateOutletTeardown(parentView, outlet) { return function() { parentView.disconnectOutlet(outlet); }; } -function findChildRouteName(route, name) { - var container = route.container; - - var childName = route.routeName === 'application' ? name : route.routeName + '.' + name; - - var hasChild = route.router.hasRoute(childName) && - (container.has('template:' + childName) || - container.has('route:' + childName)); - - return hasChild && childName; -} })();