Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember - npm Package Compare versions

Comparing version 1.0.0-pre to 1.0.0-pre.2

rsvp.js

855

application.js

@@ -11,36 +11,296 @@ //

(function() {
// ==========================================================================
// Project: Ember - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
function visit(vertex, fn, visited, path) {
var name = vertex.name,
vertices = vertex.incoming,
names = vertex.incomingNames,
len = names.length,
i;
if (!visited) {
visited = {};
}
if (!path) {
path = [];
}
if (visited.hasOwnProperty(name)) {
return;
}
path.push(name);
visited[name] = true;
for (i = 0; i < len; i++) {
visit(vertices[names[i]], fn, visited, path);
}
fn(vertex, path);
path.pop();
}
function DAG() {
this.names = [];
this.vertices = {};
}
DAG.prototype.add = function(name) {
if (!name) { return; }
if (this.vertices.hasOwnProperty(name)) {
return this.vertices[name];
}
var vertex = {
name: name, incoming: {}, incomingNames: [], hasOutgoing: false, value: null
};
this.vertices[name] = vertex;
this.names.push(name);
return vertex;
};
DAG.prototype.map = function(name, value) {
this.add(name).value = value;
};
DAG.prototype.addEdge = function(fromName, toName) {
if (!fromName || !toName || fromName === toName) {
return;
}
var from = this.add(fromName), to = this.add(toName);
if (to.incoming.hasOwnProperty(fromName)) {
return;
}
function checkCycle(vertex, path) {
if (vertex.name === toName) {
throw new Error("cycle detected: " + toName + " <- " + path.join(" <- "));
}
}
visit(from, checkCycle);
from.hasOutgoing = true;
to.incoming[fromName] = from;
to.incomingNames.push(fromName);
};
DAG.prototype.topsort = function(fn) {
var visited = {},
vertices = this.vertices,
names = this.names,
len = names.length,
i, vertex;
for (i = 0; i < len; i++) {
vertex = vertices[names[i]];
if (!vertex.hasOutgoing) {
visit(vertex, fn, visited);
}
}
};
DAG.prototype.addEdges = function(name, value, before, after) {
var i;
this.map(name, value);
if (before) {
if (typeof before === 'string') {
this.addEdge(name, before);
} else {
for (i = 0; i < before.length; i++) {
this.addEdge(name, before[i]);
}
}
}
if (after) {
if (typeof after === 'string') {
this.addEdge(after, name);
} else {
for (i = 0; i < after.length; i++) {
this.addEdge(after[i], name);
}
}
}
};
Ember.DAG = DAG;
})();
(function() {
/**
@module ember
@submodule ember-application
*/
var get = Ember.get, set = Ember.set;
/**
@class
An instance of `Ember.Application` is the starting point for every Ember.js
application. It helps to instantiate, initialize and coordinate the many
objects that make up your app.
An Ember.Application instance serves as the namespace in which you define your
application's classes. You can also override the configuration of your
Each Ember.js app has one and only one `Ember.Application` object. In fact, the very
first thing you should do in your application is create the instance:
```javascript
window.App = Ember.Application.create();
```
Typically, the application object is the only global variable. All other
classes in your app should be properties on the `Ember.Application` instance,
which highlights its first role: a global namespace.
For example, if you define a view class, it might look like this:
```javascript
App.MyView = Ember.View.extend();
```
After all of your classes are defined, call `App.initialize()` to start the
application.
By default, Ember.Application will begin listening for events on the document.
If your application is embedded inside a page, instead of controlling the
entire document, you can specify which DOM element to attach to by setting
the `rootElement` property:
Because `Ember.Application` inherits from `Ember.Namespace`, any classes
you create will have useful string representations when calling `toString()`;
see the `Ember.Namespace` documentation for more information.
MyApp = Ember.Application.create({
rootElement: $('#my-app')
});
While you can think of your `Ember.Application` as a container that holds the
other classes in your application, there are several other responsibilities
going on under-the-hood that you may want to understand.
The root of an Ember.Application must not be removed during the course of the
page's lifetime. If you have only a single conceptual application for the
entire page, and are not embedding any third-party Ember applications
in your page, use the default document root for your application.
### Event Delegation
You only need to specify the root if your page contains multiple instances
of Ember.Application.
Ember.js uses a technique called _event delegation_. This allows the framework
to set up a global, shared event listener instead of requiring each view to do
it manually. For example, instead of each view registering its own `mousedown`
listener on its associated element, Ember.js sets up a `mousedown` listener on
the `body`.
@extends Ember.Object
If a `mousedown` event occurs, Ember.js will look at the target of the event and
start walking up the DOM node tree, finding corresponding views and invoking their
`mouseDown` method as it goes.
`Ember.Application` has a number of default events that it listens for, as well
as a mapping from lowercase events to camel-cased view method names. For
example, the `keypress` event causes the `keyPress` method on the view to be
called, the `dblclick` event causes `doubleClick` to be called, and so on.
If there is a browser event that Ember.js does not listen for by default, you
can specify custom events and their corresponding view method names by setting
the application's `customEvents` property:
```javascript
App = Ember.Application.create({
customEvents: {
// add support for the loadedmetadata media
// player event
'loadedmetadata': "loadedMetadata"
}
});
```
By default, the application sets up these event listeners on the document body.
However, in cases where you are embedding an Ember.js application inside an
existing page, you may want it to set up the listeners on an element inside
the body.
For example, if only events inside a DOM element with the ID of `ember-app` should
be delegated, set your application's `rootElement` property:
```javascript
window.App = Ember.Application.create({
rootElement: '#ember-app'
});
```
The `rootElement` can be either a DOM element or a jQuery-compatible selector
string. Note that *views appended to the DOM outside the root element will not
receive events.* If you specify a custom root element, make sure you only append
views inside it!
To learn more about the advantages of event delegation and the Ember.js view layer,
and a list of the event listeners that are setup by default, visit the
[Ember.js View Layer guide](http://emberjs.com/guides/view_layer#toc_event-delegation).
### Dependency Injection
One thing you may have noticed while using Ember.js is that you define *classes*, not
*instances*. When your application loads, all of the instances are created for you.
Creating these instances is the responsibility of `Ember.Application`.
When the `Ember.Application` initializes, it will look for an `Ember.Router` class
defined on the applications's `Router` property, like this:
```javascript
App.Router = Ember.Router.extend({
// ...
});
```
If found, the router is instantiated and saved on the application's `router`
property (note the lowercase 'r'). While you should *not* reference this router
instance directly from your application code, having access to `App.router`
from the console can be useful during debugging.
After the router is created, the application loops through all of the
registered _injections_ and invokes them once for each property on the
`Ember.Application` object.
An injection is a function that is responsible for instantiating objects from
classes defined on the application. By default, the only injection registered
instantiates controllers and makes them available on the router.
For example, if you define a controller class:
```javascript
App.MyController = Ember.Controller.extend({
// ...
});
```
Your router will receive an instance of `App.MyController` saved on its
`myController` property.
Libraries on top of Ember.js can register additional injections. For example,
if your application is using Ember Data, it registers an injection that
instantiates `DS.Store`:
```javascript
Ember.Application.registerInjection({
name: 'store',
before: 'controllers',
injection: function(app, router, property) {
if (property === 'Store') {
set(router, 'store', app[property].create());
}
}
});
```
### Routing
In addition to creating your application's router, `Ember.Application` is also
responsible for telling the router when to start routing.
By default, the router will begin trying to translate the current URL into
application state once the browser emits the `DOMContentReady` event. If you
need to defer routing, you can call the application's `deferReadiness()` method.
Once routing can begin, call the `advanceReadiness()` method.
If there is any setup required before routing begins, you can implement a `ready()`
method on your app that will be invoked immediately before routing begins:
```javascript
window.App = Ember.Application.create({
ready: function() {
this.set('router.enableLogging', true);
}
});
To begin routing, you must have at a minimum a top-level controller and view.
You define these as `App.ApplicationController` and `App.ApplicationView`,
respectively. Your application will not work if you do not define these two
mandatory classes. For example:
```javascript
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
App.ApplicationController = Ember.Controller.extend();
```
@class Application
@namespace Ember
@extends Ember.Namespace
*/

@@ -51,6 +311,11 @@ Ember.Application = Ember.Namespace.extend(

/**
The root DOM element of the Application.
The root DOM element of the Application. This can be specified as an
element or a
[jQuery-compatible selector string](http://api.jquery.com/category/selectors/).
Can be specified as DOMElement or a selector string.
This is the element that will be passed to the Application's,
`eventDispatcher`, which sets up the listeners for event delegation. Every
view in your application should be a child of the element you specify here.
@property rootElement
@type DOMElement

@@ -62,2 +327,12 @@ @default 'body'

/**
The `Ember.EventDispatcher` responsible for delegating events to this
application's views.
The event dispatcher is created by the application at initialization time
and sets up event listeners on the DOM element described by the
application's `rootElement` property.
See the documentation for `Ember.EventDispatcher` for more information.
@property eventDispatcher
@type Ember.EventDispatcher

@@ -69,2 +344,23 @@ @default null

/**
The DOM events for which the event dispatcher should listen.
By default, the application's `Ember.EventDispatcher` listens
for a set of standard DOM events, such as `mousedown` and
`keyup`, and delegates them to your application's `Ember.View`
instances.
If you would like additional events to be delegated to your
views, set your `Ember.Application`'s `customEvents` property
to a hash containing the DOM event name as the key and the
corresponding view method name as the value. For example:
App = Ember.Application.create({
customEvents: {
// add support for the loadedmetadata media
// player event
'loadedmetadata': "loadedMetadata"
}
});
@property customEvents
@type Object

@@ -75,21 +371,24 @@ @default null

/** @private */
autoinit: !Ember.testing,
isInitialized: false,
init: function() {
var eventDispatcher,
rootElement = get(this, 'rootElement');
if (!this.$) { this.$ = Ember.$; }
this._super();
eventDispatcher = Ember.EventDispatcher.create({
rootElement: rootElement
});
this.createEventDispatcher();
set(this, 'eventDispatcher', eventDispatcher);
// Start off the number of deferrals at 1. This will be
// decremented by the Application's own `initialize` method.
this._readinessDeferrals = 1;
// jQuery 1.7 doesn't call the ready callback if already ready
if (Ember.$.isReady) {
Ember.run.once(this, this.didBecomeReady);
} else {
this.waitForDOMContentLoaded();
if (this.autoinit) {
var self = this;
Ember.$(document).ready(function() {
Ember.run.once(self, self.didBecomeReady);
this.$().ready(function() {
if (self.isDestroyed || self.isInitialized) return;
self.initialize();
});

@@ -99,2 +398,34 @@ }

/** @private */
createEventDispatcher: function() {
var rootElement = get(this, 'rootElement'),
eventDispatcher = Ember.EventDispatcher.create({
rootElement: rootElement
});
set(this, 'eventDispatcher', eventDispatcher);
},
waitForDOMContentLoaded: function() {
this.deferReadiness();
var self = this;
this.$().ready(function() {
self.advanceReadiness();
});
},
deferReadiness: function() {
Ember.assert("You cannot defer readiness since the `ready()` hook has already been called.", this._readinessDeferrals > 0);
this._readinessDeferrals++;
},
advanceReadiness: function() {
this._readinessDeferrals--;
if (this._readinessDeferrals === 0) {
Ember.run.once(this, this.didBecomeReady);
}
},
/**

@@ -118,11 +449,49 @@ Instantiate all controllers currently available on the namespace

router.get('postsController.router') // router
@method initialize
@param router {Ember.Router}
*/
initialize: function(router) {
var properties = Ember.A(Ember.keys(this)),
injections = get(this.constructor, 'injections'),
namespace = this, controller, name;
Ember.assert("Application initialize may only be call once", !this.isInitialized);
Ember.assert("Application not destroyed", !this.isDestroyed);
if (!router && Ember.Router.detect(namespace['Router'])) {
router = namespace['Router'].create();
router = this.setupRouter(router);
this.runInjections(router);
Ember.runLoadHooks('application', this);
this.isInitialized = true;
// At this point, any injections or load hooks that would have wanted
// to defer readiness have fired.
this.advanceReadiness();
return this;
},
/** @private */
runInjections: function(router) {
var injections = get(this.constructor, 'injections'),
graph = new Ember.DAG(),
namespace = this,
properties, i, injection;
for (i=0; i<injections.length; i++) {
injection = injections[i];
graph.addEdges(injection.name, injection.injection, injection.before, injection.after);
}
graph.topsort(function (vertex) {
var injection = vertex.value,
properties = Ember.A(Ember.keys(namespace));
properties.forEach(function(property) {
injection(namespace, router, property);
});
});
},
/** @private */
setupRouter: function(router) {
if (!router && Ember.Router.detect(this.Router)) {
router = this.Router.create();
this._createdRouter = router;

@@ -143,13 +512,3 @@ }

Ember.runLoadHooks('application', this);
injections.forEach(function(injection) {
properties.forEach(function(property) {
injection[1](namespace, router, property);
});
});
if (router && router instanceof Ember.Router) {
this.startRouting(router);
}
return router;
},

@@ -160,3 +519,4 @@

var eventDispatcher = get(this, 'eventDispatcher'),
customEvents = get(this, 'customEvents');
customEvents = get(this, 'customEvents'),
router;

@@ -166,4 +526,49 @@ eventDispatcher.setup(customEvents);

this.ready();
router = get(this, 'router');
this.createApplicationView(router);
if (router && router instanceof Ember.Router) {
this.startRouting(router);
}
},
createApplicationView: function (router) {
var rootElement = get(this, 'rootElement'),
applicationViewOptions = {},
applicationViewClass = this.ApplicationView,
applicationTemplate = Ember.TEMPLATES.application,
applicationController, applicationView;
// don't do anything unless there is an ApplicationView or application template
if (!applicationViewClass && !applicationTemplate) return;
if (router) {
applicationController = get(router, 'applicationController');
if (applicationController) {
applicationViewOptions.controller = applicationController;
}
}
if (applicationTemplate) {
applicationViewOptions.template = applicationTemplate;
}
if (!applicationViewClass) {
applicationViewClass = Ember.View;
}
applicationView = applicationViewClass.create(applicationViewOptions);
this._createdApplicationView = applicationView;
if (router) {
set(router, 'applicationView', applicationView);
}
applicationView.appendTo(rootElement);
},
/**

@@ -174,17 +579,12 @@ @private

trigger a new call to `route` whenever the URL changes.
@method startRouting
@property router {Ember.Router}
*/
startRouting: function(router) {
var location = get(router, 'location'),
rootElement = get(this, 'rootElement'),
applicationController = get(router, 'applicationController');
var location = get(router, 'location');
Ember.assert("ApplicationView and ApplicationController must be defined on your application", (this.ApplicationView && applicationController) );
Ember.assert("You must have an application template or ApplicationView defined on your application", get(router, 'applicationView') );
Ember.assert("You must have an ApplicationController defined on your application", get(router, 'applicationController') );
var applicationView = this.ApplicationView.create({
controller: applicationController
});
this._createdApplicationView = applicationView;
applicationView.appendTo(rootElement);
router.route(location.getURL());

@@ -199,6 +599,7 @@ location.onUpdateURL(function(url) {

The call will be delayed until the DOM has become ready.
@event ready
*/
ready: Ember.K,
/** @private */
willDestroy: function() {

@@ -218,19 +619,10 @@ get(this, 'eventDispatcher').destroy();

injections: Ember.A(),
registerInjection: function(options) {
var injections = get(this, 'injections'),
before = options.before,
name = options.name,
injection = options.injection,
location;
registerInjection: function(injection) {
var injections = get(this, 'injections');
if (before) {
location = injections.find(function(item) {
if (item[0] === before) { return true; }
});
location = injections.indexOf(location);
} else {
location = get(injections, 'length');
}
Ember.assert("The injection '" + injection.name + "' has already been registered", !injections.findProperty('name', injection.name));
Ember.assert("An injection cannot be registered with both a before and an after", !(injection.before && injection.after));
Ember.assert("An injection cannot be registered without an injection function", Ember.canInvoke(injection, 'injection'));
injections.splice(location, 0, [name, injection]);
injections.push(injection);
}

@@ -242,7 +634,11 @@ });

injection: function(app, router, property) {
if (!router) { return; }
if (!/^[A-Z].*Controller$/.test(property)) { return; }
var name = property.charAt(0).toLowerCase() + property.substr(1),
controller = app[property].create();
controllerClass = app[property], controller;
if(!Ember.Object.detect(controllerClass)){ return; }
controller = app[property].create();
router.set(name, controller);

@@ -258,51 +654,5 @@

})();
Ember.runLoadHooks('Ember.Application', Ember.Application);
(function() {
var get = Ember.get, set = Ember.set;
/**
This file implements the `location` API used by Ember's router.
That API is:
getURL: returns the current URL
setURL(path): sets the current URL
onUpdateURL(callback): triggers the callback when the URL changes
formatURL(url): formats `url` to be placed into `href` attribute
Calling setURL will not trigger onUpdateURL callbacks.
TODO: This, as well as the Ember.Location documentation below, should
perhaps be moved so that it's visible in the JsDoc output.
*/
/**
@class
Ember.Location returns an instance of the correct implementation of
the `location` API.
You can pass it a `implementation` ('hash', 'history', 'none') to force a
particular implementation.
*/
Ember.Location = {
create: function(options) {
var implementation = options && options.implementation;
Ember.assert("Ember.Location.create: you must specify a 'implementation' option", !!implementation);
var implementationClass = this.implementations[implementation];
Ember.assert("Ember.Location.create: " + implementation + " is not a valid implementation", !!implementationClass);
return implementationClass.create.apply(implementationClass, arguments);
},
registerImplementation: function(name, implementation) {
this.implementations[name] = implementation;
},
implementations: {}
};
})();

@@ -313,86 +663,3 @@

(function() {
var get = Ember.get, set = Ember.set;
/**
@class
Ember.HashLocation implements the location API using the browser's
hash. At present, it relies on a hashchange event existing in the
browser.
@extends Ember.Object
*/
Ember.HashLocation = Ember.Object.extend(
/** @scope Ember.HashLocation.prototype */ {
/** @private */
init: function() {
set(this, 'location', get(this, 'location') || window.location);
},
/**
@private
Returns the current `location.hash`, minus the '#' at the front.
*/
getURL: function() {
return get(this, 'location').hash.substr(1);
},
/**
@private
Set the `location.hash` and remembers what was set. This prevents
`onUpdateURL` callbacks from triggering when the hash was set by
`HashLocation`.
*/
setURL: function(path) {
get(this, 'location').hash = path;
set(this, 'lastSetURL', path);
},
/**
@private
Register a callback to be invoked when the hash changes. These
callbacks will execute when the user presses the back or forward
button, but not after `setURL` is invoked.
*/
onUpdateURL: function(callback) {
var self = this;
var guid = Ember.guidFor(this);
Ember.$(window).bind('hashchange.ember-location-'+guid, function() {
var path = location.hash.substr(1);
if (get(self, 'lastSetURL') === path) { return; }
set(self, 'lastSetURL', null);
callback(location.hash.substr(1));
});
},
/**
@private
Given a URL, formats it to be placed into the page as part
of an element's `href` attribute.
This is used, for example, when using the {{action}} helper
to generate a URL based on an event.
*/
formatURL: function(url) {
return '#'+url;
},
/** @private */
willDestroy: function() {
var guid = Ember.guidFor(this);
Ember.$(window).unbind('hashchange.ember-location-'+guid);
}
});
Ember.Location.registerImplementation('hash', Ember.HashLocation);
})();

@@ -403,163 +670,11 @@

(function() {
var get = Ember.get, set = Ember.set;
/**
@class
Ember Application
Ember.HistoryLocation implements the location API using the browser's
history.pushState API.
@extends Ember.Object
@module ember
@submodule ember-application
@requires ember-views, ember-states, ember-routing
*/
Ember.HistoryLocation = Ember.Object.extend(
/** @scope Ember.HistoryLocation.prototype */ {
/** @private */
init: function() {
set(this, 'location', get(this, 'location') || window.location);
set(this, '_initialURL', get(this, 'location').pathname);
},
/**
Will be pre-pended to path upon state change
*/
rootURL: '/',
/**
@private
Used to give history a starting reference
*/
_initialURL: null,
/**
@private
Returns the current `location.pathname`.
*/
getURL: function() {
return get(this, 'location').pathname;
},
/**
@private
Uses `history.pushState` to update the url without a page reload.
*/
setURL: function(path) {
var state = window.history.state,
initialURL = get(this, '_initialURL');
path = this.formatPath(path);
if ((initialURL !== path && !state) || (state && state.path !== path)) {
window.history.pushState({ path: path }, null, path);
}
},
/**
@private
Register a callback to be invoked whenever the browser
history changes, including using forward and back buttons.
*/
onUpdateURL: function(callback) {
var guid = Ember.guidFor(this);
Ember.$(window).bind('popstate.ember-location-'+guid, function(e) {
callback(location.pathname);
});
},
/**
@private
returns the given path appended to rootURL
*/
formatPath: function(path) {
var rootURL = get(this, 'rootURL');
if (path !== '') {
rootURL = rootURL.replace(/\/$/, '');
}
return rootURL + path;
},
/**
@private
Used when using {{action}} helper. Since no formatting
is required we just return the url given.
*/
formatURL: function(url) {
return url;
},
/** @private */
willDestroy: function() {
var guid = Ember.guidFor(this);
Ember.$(window).unbind('popstate.ember-location-'+guid);
}
});
Ember.Location.registerImplementation('history', Ember.HistoryLocation);
})();
(function() {
var get = Ember.get, set = Ember.set;
/**
@class
Ember.NoneLocation does not interact with the browser. It is useful for
testing, or when you need to manage state with your Router, but temporarily
don't want it to muck with the URL (for example when you embed your
application in a larger page).
@extends Ember.Object
*/
Ember.NoneLocation = Ember.Object.extend(
/** @scope Ember.NoneLocation.prototype */ {
path: '',
getURL: function() {
return get(this, 'path');
},
setURL: function(path) {
set(this, 'path', path);
},
onUpdateURL: function(callback) {
// We are not wired up to the browser, so we'll never trigger the callback.
},
formatURL: function(url) {
// The return value is not overly meaningful, but we do not want to throw
// errors when test code renders templates containing {{action href=true}}
// helpers.
return url;
}
});
Ember.Location.registerImplementation('none', Ember.NoneLocation);
})();
(function() {
})();
(function() {
})();

@@ -11,2 +11,13 @@ //

/**
Ember Debug
@module ember
@submodule ember-debug
*/
/**
@class Ember
*/
if ('undefined' === typeof Ember) {

@@ -36,11 +47,8 @@ Ember = {};

@static
@function
@param {String} desc
A description of the assertion. This will become the text of the Error
thrown if the assertion fails.
@method assert
@param {String} desc A description of the assertion. This will become
the text of the Error thrown if the assertion fails.
@param {Boolean} test
Must be truthy for the assertion to pass. If falsy, an exception will be
thrown.
@param {Boolean} test Must be truthy for the assertion to pass. If
falsy, an exception will be thrown.
*/

@@ -56,9 +64,6 @@ Ember.assert = function(desc, test) {

@static
@function
@param {String} message
A warning to display.
@param {Boolean} test
An optional boolean. If falsy, the warning will be displayed.
@method warn
@param {String} message A warning to display.
@param {Boolean} test An optional boolean. If falsy, the warning
will be displayed.
*/

@@ -77,9 +82,6 @@ Ember.warn = function(message, test) {

@static
@function
@param {String} message
A description of the deprecation.
@param {Boolean} test
An optional boolean. If falsy, the deprecation will be displayed.
@method deprecate
@param {String} message A description of the deprecation.
@param {Boolean} test An optional boolean. If falsy, the deprecation
will be displayed.
*/

@@ -129,9 +131,5 @@ Ember.deprecate = function(message, test) {

@static
@function
@param {String} message
A description of the deprecation.
@param {Function} func
The function to be deprecated.
@method deprecateFunc
@param {String} message A description of the deprecation.
@param {Function} func The function to be deprecated.
*/

@@ -138,0 +136,0 @@ Ember.deprecateFunc = function(message, func) {

@@ -14,9 +14,9 @@ //

(function() {
// ==========================================================================
// Project: Ember
// Copyright: ©2011 Strobe Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/**
Ember
@module ember
*/
})();

@@ -6,3 +6,3 @@ {

"dependencies": {
"convoy": "~0.3",
"convoy": "latest",
"connect": "latest",

@@ -9,0 +9,0 @@ "ember": "latest",

@@ -7,3 +7,3 @@ {

"author": "Charles Jolley",
"version": "v1.0.0-pre",
"version": "v1.0.0-pre.2",
"dependencies": {

@@ -10,0 +10,0 @@ "handlebars": "~> 1.0.0-beta.6",

@@ -10,9 +10,5 @@

asset.body = [
"var templateSpec = " + Ember.Handlebars.precompile(data) + ";",
"var Utils = Ember.Handlebars.Utils",
"module.exports = function(context, options) { ",
" options = options || {};",
" return templateSpec.call(Utils, Ember.Handlebars, context,",
" options.helpers, options.partials, options.data);",
"};"].join("\n");
"var templateSpec = "+ Ember.Handlebars.precompile(data).toString() +";",
"module.exports = Ember.Handlebars.VM.template(templateSpec);"
].join("\n");
done();

@@ -19,0 +15,0 @@ });

@@ -89,1 +89,24 @@ # Ember for Node

folder.
# Building From Source
This project checks out the ember source and builds compiled copies for use in the released version. If you want to rebuild this from source, here is what you need to do:
1. Make sure you have [node.js](http://nodejs.org) and Jake installed globally. Once
you have node.js installed you can install jake with the command
`[sudo] npm install -g jake`
2. Also make sure you have Ruby 1.9.3 or later installed as well as bundler. Once
you have ruby installed you can install bundler with `[sudo] gem install bundler`
3. Clone [the node-ember repo](http://github.com/charlesjolley/node-ember)
4. From the repo directory run `jake vendor:setup`. This should checkout the correct
versions of ember and ember-data and set them up to build
5. Run `jake diet` to actually build the assets.
Note that you only need to run `vendor:setup` once the first time you install the report or anytime the version of ember or ember-data changes. Afterwards, you should be able to run `dist` just to rebuild.
ember and ember-data are linked into this project as git submodules. To update to a newer (or older) version of ember or ember-data, cd into the vendor directory and checkout the version you want. Then cd back to the top level of the repo and commit the updates into git. Once completed, run `jake vendor:setup` again to update the contents.
**IMPORTANT:** The dist command will checkout whichever version of ember or ember-data are set in the submodule, so you must commit to git before rebuilding.

@@ -5,2 +5,3 @@ //

require("./views");
require("./states");

@@ -61,2 +62,7 @@

(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get;

@@ -91,3 +97,4 @@

/**
@class
@class Routable
@namespace Ember
@extends Ember.Mixin

@@ -98,3 +105,3 @@ */

var redirection;
this.on('connectOutlets', this, this.stashContext);
this.on('setup', this, this.stashContext);

@@ -120,2 +127,6 @@ if (redirection = get(this, 'redirectsTo')) {

setup: function() {
return this.connectOutlets.apply(this, arguments);
},
/**

@@ -127,4 +138,10 @@ @private

demand.
@method stashContext
@param manager {Ember.StateManager}
@param context
*/
stashContext: function(manager, context) {
this.router = manager;
var serialized = this.serialize(manager, context);

@@ -148,2 +165,6 @@ Ember.assert('serialize must return a hash', !serialized || typeof serialized === 'object');

In general, this will update the browser's URL.
@method updateRoute
@param manager {Ember.StateManager}
@param location {Ember.Location}
*/

@@ -165,2 +186,6 @@ updateRoute: function(manager, location) {

not the original context object.
@method absoluteRoute
@param manager {Ember.StateManager}
@param hash {Hash}
*/

@@ -199,6 +224,9 @@ absoluteRoute: function(manager, hash) {

property. This heuristic may change.
@property isRoutable
@type Boolean
*/
isRoutable: Ember.computed(function() {
return typeof get(this, 'route') === 'string';
}).cacheable(),
}),

@@ -209,2 +237,5 @@ /**

Determine if this is the last routeable state
@property isLeafRoute
@type Boolean
*/

@@ -214,3 +245,3 @@ isLeafRoute: Ember.computed(function() {

return !get(this, 'childStates').findProperty('isRoutable');
}).cacheable(),
}),

@@ -222,2 +253,5 @@ /**

string property.
@property routeMatcher
@type Ember._RouteMatcher
*/

@@ -229,3 +263,3 @@ routeMatcher: Ember.computed(function() {

}
}).cacheable(),
}),

@@ -237,2 +271,5 @@ /**

a context.
@property hasContext
@type Boolean
*/

@@ -244,3 +281,3 @@ hasContext: Ember.computed(function() {

}
}).cacheable(),
}),

@@ -253,2 +290,5 @@ /**

specified as a String.
@property modelClass
@type Ember.Object
*/

@@ -259,7 +299,7 @@ modelClass: Ember.computed(function() {

if (typeof modelType === 'string') {
return Ember.get(window, modelType);
return Ember.get(Ember.lookup, modelType);
} else {
return modelType;
}
}).cacheable(),
}),

@@ -279,2 +319,5 @@ /**

used here.
@method modelClassFor
@param namespace {Ember.Namespace}
*/

@@ -320,2 +363,6 @@ modelClassFor: function(namespace) {

fine with any class that has a `find` method.
@method deserialize
@param manager {Ember.StateManager}
@param params {Hash}
*/

@@ -342,2 +389,6 @@ deserialize: function(manager, params) {

{ blog_post_id: 12 }
@method serialize
@param manager {Ember.StateManager}
@param context
*/

@@ -361,2 +412,5 @@ serialize: function(manager, context) {

@private
@method resolvePath
@param manager {Ember.StateManager}
@param path {String}
*/

@@ -416,2 +470,6 @@ resolvePath: function(manager, path) {

on the state whose path is `/posts` with the path `/2/comments`.
@method routePath
@param manager {Ember.StateManager}
@param path {String}
*/

@@ -448,2 +506,6 @@ routePath: function(manager, path) {

state of the state it will eventually move into.
@method unroutePath
@param router {Ember.Router}
@param path {String}
*/

@@ -486,2 +548,49 @@ unroutePath: function(router, path) {

parentTemplate: Ember.computed(function() {
var state = this, parentState, template;
while (state = get(state, 'parentState')) {
if (template = get(state, 'template')) {
return template;
}
}
return 'application';
}),
_template: Ember.computed(function(key, value) {
if (arguments.length > 1) { return value; }
if (value = get(this, 'template')) {
return value;
}
// If no template was explicitly supplied convert
// the class name into a template name. For example,
// App.PostRoute will return `post`.
var className = this.constructor.toString(), baseName;
if (/^[^\[].*Route$/.test(className)) {
baseName = className.match(/([^\.]+\.)*([^\.]+)/)[2];
baseName = baseName.replace(/Route$/, '');
return baseName.charAt(0).toLowerCase() + baseName.substr(1);
}
}),
render: function(options) {
options = options || {};
var template = options.template || get(this, '_template'),
parentTemplate = options.into || get(this, 'parentTemplate'),
controller = get(this.router, parentTemplate + "Controller");
var viewName = Ember.String.classify(template) + "View",
viewClass = get(get(this.router, 'namespace'), viewName);
viewClass = (viewClass || Ember.View).extend({
templateName: template
});
controller.set('view', viewClass.create());
},
/**

@@ -491,2 +600,6 @@ The `connectOutlets` event will be triggered once a

route's context.
@event connectOutlets
@param router {Ember.Router}
@param [context*]
*/

@@ -498,2 +611,4 @@ connectOutlets: Ember.K,

URL changes due to the back/forward button
@event navigateAway
*/

@@ -509,5 +624,12 @@ navigateAway: Ember.K

/**
@class
@extends Ember.Routable
@module ember
@submodule ember-routing
*/
/**
@class Route
@namespace Ember
@extends Ember.State
@uses Ember.Routable
*/
Ember.Route = Ember.State.extend(Ember.Routable);

@@ -524,2 +646,8 @@

/**
@class _RouteMatcher
@namespace Ember
@private
@extends Ember.Object
*/
Ember._RouteMatcher = Ember.Object.extend({

@@ -541,5 +669,10 @@ state: null,

var regex = escaped.replace(/:([a-z_]+)(?=$|\/)/gi, function(match, id) {
var regex = escaped.replace(/(:|(?:\\\*))([a-z_]+)(?=$|\/)/gi, function(match, type, id) {
identifiers[count++] = id;
return "([^/]+)";
switch (type) {
case ":":
return "([^/]+)";
case "\\*":
return "(.+)";
}
});

@@ -573,3 +706,3 @@

id = identifiers[i];
route = route.replace(new RegExp(":" + id), hash[id]);
route = route.replace(new RegExp("(:|(\\*))" + id), hash[id]);
}

@@ -585,4 +718,378 @@ return route;

(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/*
This file implements the `location` API used by Ember's router.
That API is:
getURL: returns the current URL
setURL(path): sets the current URL
onUpdateURL(callback): triggers the callback when the URL changes
formatURL(url): formats `url` to be placed into `href` attribute
Calling setURL will not trigger onUpdateURL callbacks.
TODO: This should perhaps be moved so that it's visible in the doc output.
*/
/**
Ember.Location returns an instance of the correct implementation of
the `location` API.
You can pass it a `implementation` ('hash', 'history', 'none') to force a
particular implementation.
@class Location
@namespace Ember
@static
*/
Ember.Location = {
create: function(options) {
var implementation = options && options.implementation;
Ember.assert("Ember.Location.create: you must specify a 'implementation' option", !!implementation);
var implementationClass = this.implementations[implementation];
Ember.assert("Ember.Location.create: " + implementation + " is not a valid implementation", !!implementationClass);
return implementationClass.create.apply(implementationClass, arguments);
},
registerImplementation: function(name, implementation) {
this.implementations[name] = implementation;
},
implementations: {}
};
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/**
Ember.NoneLocation does not interact with the browser. It is useful for
testing, or when you need to manage state with your Router, but temporarily
don't want it to muck with the URL (for example when you embed your
application in a larger page).
@class NoneLocation
@namespace Ember
@extends Ember.Object
*/
Ember.NoneLocation = Ember.Object.extend({
path: '',
getURL: function() {
return get(this, 'path');
},
setURL: function(path) {
set(this, 'path', path);
},
onUpdateURL: function(callback) {
// We are not wired up to the browser, so we'll never trigger the callback.
},
formatURL: function(url) {
// The return value is not overly meaningful, but we do not want to throw
// errors when test code renders templates containing {{action href=true}}
// helpers.
return url;
}
});
Ember.Location.registerImplementation('none', Ember.NoneLocation);
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/**
Ember.HashLocation implements the location API using the browser's
hash. At present, it relies on a hashchange event existing in the
browser.
@class HashLocation
@namespace Ember
@extends Ember.Object
*/
Ember.HashLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
},
/**
@private
Returns the current `location.hash`, minus the '#' at the front.
@method getURL
*/
getURL: function() {
return get(this, 'location').hash.substr(1);
},
/**
@private
Set the `location.hash` and remembers what was set. This prevents
`onUpdateURL` callbacks from triggering when the hash was set by
`HashLocation`.
@method setURL
@param path {String}
*/
setURL: function(path) {
get(this, 'location').hash = path;
set(this, 'lastSetURL', path);
},
/**
@private
Register a callback to be invoked when the hash changes. These
callbacks will execute when the user presses the back or forward
button, but not after `setURL` is invoked.
@method onUpdateURL
@param callback {Function}
*/
onUpdateURL: function(callback) {
var self = this;
var guid = Ember.guidFor(this);
Ember.$(window).bind('hashchange.ember-location-'+guid, function() {
var path = location.hash.substr(1);
if (get(self, 'lastSetURL') === path) { return; }
set(self, 'lastSetURL', null);
callback(location.hash.substr(1));
});
},
/**
@private
Given a URL, formats it to be placed into the page as part
of an element's `href` attribute.
This is used, for example, when using the {{action}} helper
to generate a URL based on an event.
@method formatURL
@param url {String}
*/
formatURL: function(url) {
return '#'+url;
},
willDestroy: function() {
var guid = Ember.guidFor(this);
Ember.$(window).unbind('hashchange.ember-location-'+guid);
}
});
Ember.Location.registerImplementation('hash', Ember.HashLocation);
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
var popstateReady = false;
/**
Ember.HistoryLocation implements the location API using the browser's
history.pushState API.
@class HistoryLocation
@namespace Ember
@extends Ember.Object
*/
Ember.HistoryLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
this.initState();
},
/**
@private
Used to set state on first call to setURL
@method initState
*/
initState: function() {
this.replaceState(get(this, 'location').pathname);
set(this, 'history', window.history);
},
/**
Will be pre-pended to path upon state change
@property rootURL
@default '/'
*/
rootURL: '/',
/**
@private
Returns the current `location.pathname`.
@method getURL
*/
getURL: function() {
return get(this, 'location').pathname;
},
/**
@private
Uses `history.pushState` to update the url without a page reload.
@method setURL
@param path {String}
*/
setURL: function(path) {
path = this.formatURL(path);
if (this.getState().path !== path) {
popstateReady = true;
this.pushState(path);
}
},
/**
@private
Get the current `history.state`
@method getState
*/
getState: function() {
return get(this, 'history').state;
},
/**
@private
Pushes a new state
@method pushState
@param path {String}
*/
pushState: function(path) {
window.history.pushState({ path: path }, null, path);
},
/**
@private
Replaces the current state
@method replaceState
@param path {String}
*/
replaceState: function(path) {
window.history.replaceState({ path: path }, null, path);
},
/**
@private
Register a callback to be invoked whenever the browser
history changes, including using forward and back buttons.
@method onUpdateURL
@param callback {Function}
*/
onUpdateURL: function(callback) {
var guid = Ember.guidFor(this);
Ember.$(window).bind('popstate.ember-location-'+guid, function(e) {
if(!popstateReady) {
return;
}
callback(location.pathname);
});
},
/**
@private
Used when using `{{action}}` helper. The url is always appended to the rootURL.
@method formatURL
@param url {String}
*/
formatURL: function(url) {
var rootURL = get(this, 'rootURL');
if (url !== '') {
rootURL = rootURL.replace(/\/$/, '');
}
return rootURL + url;
},
willDestroy: function() {
var guid = Ember.guidFor(this);
Ember.$(window).unbind('popstate.ember-location-'+guid);
}
});
Ember.Location.registerImplementation('history', Ember.HistoryLocation);
})();
(function() {
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
var merge = function(original, hash) {

@@ -598,4 +1105,2 @@ for (var prop in hash) {

/**
@class
`Ember.Router` is the subclass of `Ember.StateManager` responsible for providing URL-based

@@ -675,3 +1180,3 @@ application state detection. The `Ember.Router` instance of an application detects the browser URL

then to the substate 'bRoute'.
## Adding Nested Routes to a Router

@@ -684,3 +1189,3 @@ Routes can contain nested subroutes each with their own `route` property describing the nested

to when the base route is detected in the URL:
Given the following application code:

@@ -692,16 +1197,16 @@

aRoute: Ember.Route.extend({
route: '/theBaseRouteForThisSet',
route: '/theBaseRouteForThisSet',
indexSubRoute: Ember.Route.extend({
route: '/',
route: '/'
}),
subRouteOne: Ember.Route.extend({
route: '/subroute1
route: '/subroute1'
}),
subRouteTwo: Ember.Route.extend({
route: '/subRoute2'
})
})

@@ -715,6 +1220,6 @@ })

at path 'root.aRoute' and then transition to state 'indexSubRoute'.
When the application is loaded at '/theBaseRouteForThisSet/subRoute1' the Router will transition to
the route at path 'root.aRoute' and then transition to state 'subRouteOne'.
## Route Transition Events

@@ -766,3 +1271,3 @@ Transitioning between Ember.Route instances (including the transition into the detected

back button) the `deserialize` method of the URL's matching Ember.Route will be called with
the application's router as its first argument and a hash of the URLs dynamic segments and values
the application's router as its first argument and a hash of the URL's dynamic segments and values
as its second argument.

@@ -803,4 +1308,4 @@

`serialize` method is called with the Route's router as the first argument and the Route's
context as the second argument. The return value of `serialize` will be use to populate the
dynamic segments and should be a object with keys that match the names of the dynamic sections.
context as the second argument. The return value of `serialize` will be used to populate the
dynamic segments and should be an object with keys that match the names of the dynamic sections.

@@ -894,3 +1399,3 @@ Given the following route structure:

During application initialization Ember will detect properties of the application ending in 'Controller',
create singleton instances of each class, and assign them as a properties on the router. The property name
create singleton instances of each class, and assign them as properties on the router. The property name
will be the UpperCamel name converted to lowerCamel format. These controller classes should be subclasses

@@ -900,12 +1405,14 @@ of Ember.ObjectController, Ember.ArrayController, Ember.Controller, or a custom Ember.Object that includes the

App = Ember.Application.create({
FooController: Ember.Object.create(Ember.ControllerMixin),
Router: Ember.Router.extend({ ... })
});
``` javascript
App = Ember.Application.create({
FooController: Ember.Object.create(Ember.ControllerMixin),
Router: Ember.Router.extend({ ... })
});
App.get('router.fooController'); // instance of App.FooController
App.get('router.fooController'); // instance of App.FooController
```
The controller singletons will have their `namespace` property set to the application and their `target`
property set to the application's router singleton for easy integration with Ember's user event system.
See 'Changing View Hierarchy in Response To State Change' and 'Responding to User-initiated Events'
See 'Changing View Hierarchy in Response To State Change' and 'Responding to User-initiated Events.'

@@ -919,27 +1426,31 @@ ## Responding to User-initiated Events

App = Ember.Application.create({
Router: Ember.Router.extend({
root: Ember.Route.extend({
aRoute: Ember.Route.extend({
route: '/',
anActionOnTheRouter: function(router, context) {
router.transitionTo('anotherState', context);
}
})
anotherState: Ember.Route.extend({
route: '/differentUrl',
connectOutlets: function(router, context) {
``` javascript
App = Ember.Application.create({
Router: Ember.Router.extend({
root: Ember.Route.extend({
aRoute: Ember.Route.extend({
route: '/',
anActionOnTheRouter: function(router, context) {
router.transitionTo('anotherState', context);
}
})
anotherState: Ember.Route.extend({
route: '/differentUrl',
connectOutlets: function(router, context) {
}
})
})
}
})
});
App.initialize();
})
})
});
App.initialize();
```
The following template:
<script type="text/x-handlebars" data-template-name="aView">
<h1><a {{action anActionOnTheRouter}}>{{title}}</a></h1>
</script>
``` handlebars
<script type="text/x-handlebars" data-template-name="aView">
<h1><a {{action anActionOnTheRouter}}>{{title}}</a></h1>
</script>
```

@@ -953,12 +1464,15 @@ Will delegate `click` events on the rendered `h1` to the application's router instance. In this case the

<script type="text/x-handlebars" data-template-name="photos">
{{#each photo in controller}}
<h1><a {{action showPhoto photo}}>{{title}}</a></h1>
{{/each}}
</script>
``` handlebars
<script type="text/x-handlebars" data-template-name="photos">
{{#each photo in controller}}
<h1><a {{action showPhoto photo}}>{{title}}</a></h1>
{{/each}}
</script>
```
See Handlebars.helpers.action for additional usage examples.
See `Handlebars.helpers.action` for additional usage examples.
## Changing View Hierarchy in Response To State Change
Changes in application state that change the URL should be accompanied by associated changes in view

@@ -968,21 +1482,23 @@ hierarchy. This can be accomplished by calling 'connectOutlet' on the injected controller singletons from

App = Ember.Application.create({
OneController: Ember.ObjectController.extend(),
OneView: Ember.View.extend(),
``` javascript
App = Ember.Application.create({
OneController: Ember.ObjectController.extend(),
OneView: Ember.View.extend(),
AnotherController: Ember.ObjectController.extend(),
AnotherView: Ember.View.extend(),
AnotherController: Ember.ObjectController.extend(),
AnotherView: Ember.View.extend(),
Router: Ember.Router.extend({
root: Ember.Route.extend({
aRoute: Ember.Route.extend({
route: '/',
connectOutlets: function(router, context) {
router.get('oneController').connectOutlet('another');
},
})
})
Router: Ember.Router.extend({
root: Ember.Route.extend({
aRoute: Ember.Route.extend({
route: '/',
connectOutlets: function(router, context) {
router.get('oneController').connectOutlet('another');
},
})
});
App.initialize();
})
})
});
App.initialize();
```

@@ -999,2 +1515,4 @@

@class Router
@namespace Ember
@extends Ember.StateManager

@@ -1006,3 +1524,4 @@ */

/**
@property {String}
@property initialState
@type String
@default 'root'

@@ -1017,5 +1536,8 @@ */

* 'hash': Uses URL fragment identifiers (like #/blog/1) for routing.
* 'history': Uses the browser's history.pushstate API for routing. Only works in
modern browsers with pushstate support.
* 'none': Does not read or set the browser URL, but still allows for
routing to happen. Useful for testing.
@property location
@type String

@@ -1030,2 +1552,3 @@ @default 'hash'

@property rootURL
@type String

@@ -1037,10 +1560,2 @@ @default '/'

/**
On router, transitionEvent should be called connectOutlets
@property {String}
@default 'connectOutlets'
*/
transitionEvent: 'connectOutlets',
transitionTo: function() {

@@ -1059,2 +1574,3 @@ this.abortRoutingPromises();

try {
path = path.replace(get(this, 'rootURL'), '');
path = path.replace(/^(?=[^\/])/, "/");

@@ -1091,4 +1607,4 @@

Ember.assert(Ember.String.fmt("Could not find route with path '%@'", [path]), !!state);
Ember.assert("To get a URL for a state, it must have a `route` property.", !!get(state, 'routeMatcher'));
Ember.assert(Ember.String.fmt("Could not find route with path '%@'", [path]), state);
Ember.assert(Ember.String.fmt("To get a URL for the state '%@', it must have a `route` property.", [path]), get(state, 'routeMatcher'));

@@ -1106,7 +1622,7 @@ var location = get(this, 'location'),

Ember.assert(Ember.String.fmt("You must specify a target state for event '%@' in order to link to it in the current state '%@'.", [eventName, get(currentState, 'path')]), !!targetStateName);
Ember.assert(Ember.String.fmt("You must specify a target state for event '%@' in order to link to it in the current state '%@'.", [eventName, get(currentState, 'path')]), targetStateName);
var targetState = this.findStateByPath(currentState, targetStateName);
Ember.assert("Your target state name " + targetStateName + " for event " + eventName + " did not resolve to a state", !!targetState);
Ember.assert("Your target state name " + targetStateName + " for event " + eventName + " did not resolve to a state", targetState);

@@ -1118,3 +1634,2 @@ var hash = this.serializeRecursively(targetState, contexts, {});

/** @private */
serializeRecursively: function(state, contexts, hash) {

@@ -1139,5 +1654,2 @@ var parentState,

/**
@private
*/
handleStatePromises: function(states, complete) {

@@ -1172,4 +1684,22 @@ this.abortRoutingPromises();

/** @private */
moveStatesIntoRoot: function() {
this.root = Ember.Route.extend();
for (var name in this) {
if (name === "constructor") { continue; }
var state = this[name];
if (state instanceof Ember.Route || Ember.Route.detect(state)) {
this.root[name] = state;
delete this[name];
}
}
},
init: function() {
if (!this.root) {
this.moveStatesIntoRoot();
}
this._super();

@@ -1186,5 +1716,19 @@

}
this.assignRouter(this, this);
},
/** @private */
assignRouter: function(state, router) {
state.router = router;
var childStates = state.states;
if (childStates) {
for (var stateName in childStates) {
if (!childStates.hasOwnProperty(stateName)) { continue; }
this.assignRouter(childStates[stateName], router);
}
}
},
willDestroy: function() {

@@ -1200,9 +1744,11 @@ get(this, 'location').destroy();

(function() {
// ==========================================================================
// Project: Ember Routing
// Copyright: ©2012 Tilde Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/**
Ember Routing
@module ember
@submodule ember-routing
@requires ember-states
*/
})();

@@ -12,5 +12,11 @@ //

/**
@class
@module ember
@submodule ember-states
*/
/**
@class State
@namespace Ember
@extends Ember.Object
@uses Ember.Evented
*/

@@ -24,2 +30,3 @@ Ember.State = Ember.Object.extend(Ember.Evented,

@property parentState
@type Ember.State

@@ -33,2 +40,3 @@ */

@property name
@type String

@@ -41,4 +49,4 @@ */

@property path
@type String
@readOnly
*/

@@ -54,3 +62,3 @@ path: Ember.computed(function() {

return path;
}).property().cacheable(),
}).property(),

@@ -62,2 +70,5 @@ /**

also call methods with the given name.
@method trigger
@param name
*/

@@ -71,3 +82,2 @@ trigger: function(name) {

/** @private */
init: function() {

@@ -112,3 +122,2 @@ var states = get(this, 'states'), foundStates;

/** @private */
setupChild: function(states, name, value) {

@@ -129,2 +138,3 @@ if (!value) { return false; }

states[name] = value;
return value;
}

@@ -149,2 +159,3 @@ },

@property isLeaf
@type Boolean

@@ -154,3 +165,3 @@ */

return !get(this, 'childStates').length;
}).cacheable(),
}),

@@ -160,2 +171,5 @@ /**

By default we assume all states take contexts.
@property hasContext
@default true
*/

@@ -167,3 +181,3 @@ hasContext: true,

@event
@event setup
@param {Ember.StateManager} manager

@@ -178,3 +192,3 @@ @param context

@event
@event enter
@param {Ember.StateManager} manager

@@ -187,3 +201,3 @@ */

@event
@event exit
@param {Ember.StateManager} manager

@@ -194,52 +208,54 @@ */

var Event = Ember.$ && Ember.$.Event;
Ember.State.reopenClass({
Ember.State.reopenClass(
/** @scope Ember.State */{
/**
@static
Creates an action function for transitioning to the named state while preserving context.
Creates an action function for transitioning to the named state while preserving context.
The following example StateManagers are equivalent:
The following example StateManagers are equivalent:
aManager = Ember.StateManager.create({
stateOne: Ember.State.create({
changeToStateTwo: Ember.State.transitionTo('stateTwo')
}),
stateTwo: Ember.State.create({})
})
aManager = Ember.StateManager.create({
stateOne: Ember.State.create({
changeToStateTwo: Ember.State.transitionTo('stateTwo')
}),
stateTwo: Ember.State.create({})
})
bManager = Ember.StateManager.create({
stateOne: Ember.State.create({
changeToStateTwo: function(manager, context){
manager.transitionTo('stateTwo', context)
}
}),
stateTwo: Ember.State.create({})
})
bManager = Ember.StateManager.create({
stateOne: Ember.State.create({
changeToStateTwo: function(manager, context){
manager.transitionTo('stateTwo', context)
}
}),
stateTwo: Ember.State.create({})
})
@method transitionTo
@static
@param {String} target
*/
@param {String} target
*/
transitionTo: function(target) {
var event = function(stateManager, context) {
if (Event && context instanceof Event) {
if (context.hasOwnProperty('context')) {
context = context.context;
} else {
// If we received an event and it doesn't contain
// a context, don't pass along a superfluous
// context to the target of the event.
return stateManager.transitionTo(target);
var transitionFunction = function(stateManager, contextOrEvent) {
var contexts = [], transitionArgs,
Event = Ember.$ && Ember.$.Event;
if (contextOrEvent && (Event && contextOrEvent instanceof Event)) {
if (contextOrEvent.hasOwnProperty('contexts')) {
contexts = contextOrEvent.contexts.slice();
}
}
else {
contexts = [].slice.call(arguments, 1);
}
stateManager.transitionTo(target, context);
contexts.unshift(target);
stateManager.transitionTo.apply(stateManager, contexts);
};
event.transitionTarget = target;
transitionFunction.transitionTarget = target;
return event;
return transitionFunction;
}
});

@@ -252,7 +268,10 @@

(function() {
/**
@module ember
@submodule ember-states
*/
var get = Ember.get, set = Ember.set, fmt = Ember.String.fmt;
var arrayForEach = Ember.ArrayPolyfills.forEach;
/**
@private
A Transition takes the enter, exit and resolve states and normalizes

@@ -263,2 +282,5 @@ them:

* adds in `initialState`s
@class Transition
@private
*/

@@ -275,4 +297,2 @@ var Transition = function(raw) {

/**
@private
Normalize the passed in enter, exit and resolve states.

@@ -282,2 +302,3 @@

@method normalize
@param {Ember.StateManager} manager the state manager running the transition

@@ -294,4 +315,2 @@ @param {Array} contexts a list of contexts passed into `transitionTo`

/**
@private
Match each of the contexts passed to `transitionTo` to a state.

@@ -301,2 +320,3 @@ This process may also require adding additional enter and exit

@method matchContextsToStates
@param {Array} contexts a list of contexts passed into `transitionTo`

@@ -374,5 +394,5 @@ */

/**
@private
Add any `initialState`s to the list of enter states.
Add any `initialState`s to the list of enter states.
@method addInitialStates
*/

@@ -395,4 +415,2 @@ addInitialStates: function() {

/**
@private
Remove any states that were added because the number of contexts

@@ -402,2 +420,3 @@ exceeded the number of explicit enter states, but the context has

@method removeUnchangedContexts
@param {Ember.StateManager} manager passed in to look up the last

@@ -425,4 +444,2 @@ context for a states

/**
@class
StateManager is part of Ember's implementation of a finite state machine. A StateManager

@@ -791,10 +808,16 @@ instance manages a number of properties that are instances of `Ember.State`,

})
@class StateManager
@namespace Ember
@extends Ember.State
**/
Ember.StateManager = Ember.State.extend(
/** @scope Ember.StateManager.prototype */ {
Ember.StateManager = Ember.State.extend({
/**
@private
/**
When creating a new statemanager, look for a default state to transition
into. This state can either be named `start`, or can be specified using the
`initialState` property.
@method init
*/

@@ -842,4 +865,4 @@ init: function() {

@property currentState
@type Ember.State
@readOnly
*/

@@ -849,5 +872,17 @@ currentState: null,

/**
The path of the current state. Returns a string representation of the current
state.
@property currentPath
@type String
*/
currentPath: Ember.computed('currentState', function() {
return get(this, 'currentState.path');
}),
/**
The name of transitionEvent that this stateManager will dispatch
@property {String}
@property transitionEvent
@type String
@default 'setup'

@@ -862,2 +897,3 @@ */

@property errorOnUnhandledEvents
@type Boolean

@@ -868,11 +904,21 @@ @default true

send: function(event, context) {
send: function(event) {
var contexts, sendRecursiveArguments;
Ember.assert('Cannot send event "' + event + '" while currentState is ' + get(this, 'currentState'), get(this, 'currentState'));
return this.sendRecursively(event, get(this, 'currentState'), context);
contexts = [].slice.call(arguments, 1);
sendRecursiveArguments = contexts;
sendRecursiveArguments.unshift(event, get(this, 'currentState'));
return this.sendRecursively.apply(this, sendRecursiveArguments);
},
sendRecursively: function(event, currentState, context) {
sendRecursively: function(event, currentState) {
var log = this.enableLogging,
action = currentState[event];
action = currentState[event],
contexts, sendRecursiveArguments, actionArguments;
contexts = [].slice.call(arguments, 2);
// Test to see if the action is a method that

@@ -886,7 +932,15 @@ // can be invoked. Don't blindly check just for

if (log) { Ember.Logger.log(fmt("STATEMANAGER: Sending event '%@' to state %@.", [event, get(currentState, 'path')])); }
return action.call(currentState, this, context);
actionArguments = contexts;
actionArguments.unshift(this);
return action.apply(currentState, actionArguments);
} else {
var parentState = get(currentState, 'parentState');
if (parentState) {
return this.sendRecursively(event, parentState, context);
sendRecursiveArguments = contexts;
sendRecursiveArguments.unshift(event, parentState);
return this.sendRecursively.apply(this, sendRecursiveArguments);
} else if (get(this, 'errorOnUnhandledEvent')) {

@@ -913,5 +967,6 @@ throw new Ember.Error(this.toString() + " could not respond to event " + event + " in state " + get(this, 'currentState.path') + ".");

@method getStateByPath
@param {Ember.State} root the state to start searching from
@param {String} path the state path to follow
@returns {Ember.State} the state at the end of the path
@return {Ember.State} the state at the end of the path
*/

@@ -922,3 +977,3 @@ getStateByPath: function(root, path) {

for (var i=0, l=parts.length; i<l; i++) {
for (var i=0, len=parts.length; i<len; i++) {
state = get(get(state, 'states'), parts[i]);

@@ -943,28 +998,30 @@ if (!state) { break; }

/**
@private
A state stores its child states in its `states` hash.
This code takes a path like `posts.show` and looks
up `origin.states.posts.states.show`.
up `root.states.posts.states.show`.
It returns a list of all of the states from the
origin, which is the list of states to call `enter`
root, which is the list of states to call `enter`
on.
@method getStatesInPath
@param root
@param path
*/
findStatesByPath: function(origin, path) {
getStatesInPath: function(root, path) {
if (!path || path === "") { return undefined; }
var r = path.split('.'),
ret = [];
var parts = path.split('.'),
result = [],
states,
state;
for (var i=0, len = r.length; i < len; i++) {
var states = get(origin, 'states');
for (var i=0, len=parts.length; i<len; i++) {
states = get(root, 'states');
if (!states) { return undefined; }
var s = get(states, r[i]);
if (s) { origin = s; ret.push(s); }
state = get(states, parts[i]);
if (state) { root = state; result.push(state); }
else { return undefined; }
}
return ret;
return result;
},

@@ -1001,3 +1058,3 @@

var enterStates = this.findStatesByPath(currentState, path),
var enterStates = this.getStatesInPath(currentState, path),
exitStates = [],

@@ -1044,3 +1101,3 @@ resolveState = currentState;

if (!resolveState) {
enterStates = this.findStatesByPath(this, path);
enterStates = this.getStatesInPath(this, path);
if (!enterStates) {

@@ -1051,3 +1108,3 @@ Ember.assert('Could not find state for path: "'+path+'"');

}
enterStates = this.findStatesByPath(resolveState, path);
enterStates = this.getStatesInPath(resolveState, path);
}

@@ -1142,9 +1199,11 @@

(function() {
// ==========================================================================
// Project: Ember Statecharts
// Copyright: ©2011 Living Social Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/**
Ember States
@module ember
@submodule ember-states
@requires ember-runtime
*/
})();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc