Skip to content

rebased against upstream/master #1352

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5444456
refactor($state): use map function in get()
nateabele Apr 28, 2014
e7ac86a
feat($state): params are now observable
nateabele Apr 22, 2014
bbe64fa
style($stateParams): make JSHint stop yelling
nateabele Apr 22, 2014
a6888a2
refactor($state): use helper funcs to scope params
nateabele Apr 28, 2014
d254057
style($state): fixing doc indent
nateabele Apr 28, 2014
9f58507
test($stateParams): verify observation behavior
nateabele Apr 28, 2014
02c5033
fix($resolve): Resolves only inherit from immediate parent fixes #702
asperry152 Jul 19, 2014
041c71b
WIP
nateabele May 30, 2014
0b70489
chore(grunt): Add karma.watch task
christopherthielen Sep 8, 2014
3684605
chore(lint): linted
christopherthielen Sep 8, 2014
d0486de
chore(common): Added _-like functions: indexBy, pick, omit, pluck, ma…
christopherthielen Sep 8, 2014
641c60e
feat($resolve): Super-duper-lazy Resolvable system
christopherthielen Sep 8, 2014
2f31e1c
Merge pull request #6 from nateabele/resolvable-rebase
christopherthielen Sep 8, 2014
862cf48
feat($state): params are now observable
nateabele Apr 22, 2014
5c5509f
style($stateParams): make JSHint stop yelling
nateabele Apr 22, 2014
4059545
refactor($state): use helper funcs to scope params
nateabele Apr 28, 2014
79c4649
style($state): fixing doc indent
nateabele Apr 28, 2014
db5ee64
test($stateParams): verify observation behavior
nateabele Apr 28, 2014
99d53ac
WIP
nateabele May 30, 2014
f76ae5d
chore(grunt): Add karma.watch task
christopherthielen Sep 8, 2014
96ce0db
chore(lint): linted
christopherthielen Sep 8, 2014
70514e6
chore(common): Added _-like functions: indexBy, pick, omit, pluck, ma…
christopherthielen Sep 8, 2014
191f38d
feat($resolve): Super-duper-lazy Resolvable system
christopherthielen Sep 8, 2014
faa2ee9
chore(lint): linted
christopherthielen Sep 9, 2014
2b6ffd9
Merged from upstream-rebase
christopherthielen Sep 10, 2014
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
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ module.exports = function (grunt) {
background: {
background: true,
browsers: [ grunt.option('browser') || 'PhantomJS' ]
},
watch: {
configFile: 'config/karma.js',
singleRun: false,
autoWatch: true,
autoWatchInterval: 1
}
},
changelog: {
Expand Down
5 changes: 5 additions & 0 deletions files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ routerFiles = {
'src/resolve.js',
'src/templateFactory.js',
'src/urlMatcherFactory.js',
'src/transition.js',
'src/urlRouter.js',
'src/state.js',
'src/view.js',
Expand All @@ -16,6 +17,10 @@ routerFiles = {
'test/testUtils.js'
],
test: [
// 'test/stateSpec.js',
// 'test/resolveSpec.js',
// 'test/urlMatcherFactorySpec.js',
// 'test/urlRouterSpec.js',
'test/*Spec.js',
'test/compat/matchers.js'
],
Expand Down
20 changes: 16 additions & 4 deletions sample/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ angular.module('uiRouterSample', [
)

.config(
[ '$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
[ '$stateProvider', '$urlRouterProvider', '$urlMatcherFactoryProvider',
function ($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvider) {

$urlMatcherFactoryProvider.type('contact', ['contacts', function(contacts) {
return {
encode: function(contact) {
return contact.id;
},
decode: function(id) {
return contacts.get(id);
},
pattern: /[0-9]{1,4}/
};
}]);

/////////////////////////////
// Redirects and Otherwise //
Expand All @@ -34,8 +46,8 @@ angular.module('uiRouterSample', [

// The `when` method says if the url is ever the 1st param, then redirect to the 2nd param
// Here we are just setting up some convenience urls.
.when('/c?id', '/contacts/:id')
.when('/user/:id', '/contacts/:id')
// .when('/c?id', '/contacts/:id')
// .when('/user/:id', '/contacts/:id')

// If the url is ever invalid, e.g. '/asdf', then redirect to '/' aka the home state
.otherwise('/');
Expand Down
5 changes: 3 additions & 2 deletions sample/app/contacts/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ angular.module('uiRouterSample.contacts', [
.config(
[ '$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {

$stateProvider
//////////////
// Contacts //
Expand Down Expand Up @@ -95,7 +96,7 @@ angular.module('uiRouterSample.contacts', [
// So its url will end up being '/contacts/{contactId:[0-9]{1,8}}'. When the
// url becomes something like '/contacts/42' then this state becomes active
// and the $stateParams object becomes { contactId: 42 }.
url: '/{contactId:[0-9]{1,4}}',
url: '/{contact:contact}',

// If there is more than a single ui-view in the parent template, or you would
// like to target a ui-view from even higher up the state tree, you can use the
Expand All @@ -113,7 +114,7 @@ angular.module('uiRouterSample.contacts', [
templateUrl: 'app/contacts/contacts.detail.html',
controller: ['$scope', '$stateParams', 'utils',
function ( $scope, $stateParams, utils) {
$scope.contact = utils.findById($scope.contacts, $stateParams.contactId);
$scope.contact = $stateParams.contact
}]
},

Expand Down
66 changes: 65 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,74 @@ function filterByKeys(keys, values) {
var filtered = {};

forEach(keys, function (name) {
filtered[name] = values[name];
if (isDefined(values[name])) filtered[name] = values[name];
});
return filtered;
}

// like _.indexBy
// when you know that your index values will be unique, or you want last-one-in to win
function indexBy(array, propName) {
var result = {};
forEach(array, function(item) {
result[item[propName]] = item;
});
return result;
}

// extracted from underscore.js
// Return a copy of the object only containing the whitelisted properties.
function pick(obj) {
var copy = {};
var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
forEach(keys, function(key) {
if (key in obj) copy[key] = obj[key];
});
return copy;
}

// extracted from underscore.js
// Return a copy of the object omitting the blacklisted properties.
function omit(obj) {
var copy = {};
var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
for (var key in obj) {
if (keys.indexOf(key) == -1) copy[key] = obj[key];
}
return copy;
}

function pluck(collection, key) {
var result = isArray(collection) ? [] : {};

forEach(collection, function(val, i) {
result[i] = isFunction(key) ? key(val) : val[key];
});
return result;
}

function map(collection, callback) {
var result = isArray(collection) ? [] : {};

forEach(collection, function(val, i) {
result[i] = callback(val, i);
});
return result;
}

function flattenPrototypeChain(obj) {
var objs = [];
do {
objs.push(obj);
} while ((obj = Object.getPrototypeOf(obj)));
objs.reverse();

var result = {};
forEach(objs, function(obj) {
extend(result, obj);
});
return result;
}
/**
* @ngdoc overview
* @name ui.router.util
Expand Down
Loading