-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstates.js
73 lines (67 loc) · 2.24 KB
/
states.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {ContactsStorage} from '../global/dataSources';
import Contacts from './Contacts';
import ContactView from './ContactView';
import EditContact from './EditContact';
/**
* This state displays the contact list.
* It also provides a nested ui-view (viewport) for child states to fill in.
*
* The contacts are fetched using a resolve.
*/
const contactsState = {
parent: 'app', // declares that 'contacts' is a child of 'app'
name: "contacts",
url: "/contacts",
resolve: {
// Resolve all the contacts. The resolved contacts are injected as props into the Contacts component.
contacts: () => ContactsStorage.all()
},
data: { requiresAuth: true },
component: Contacts
};
/**
* This state displays a single contact.
* The contact to display is fetched using a resolve, based on the `contactId` parameter.
*/
const viewContactState = {
name: 'contacts.contact',
url: '/:contactId',
resolve: {
// Resolve the contact, based on the contactId parameter value.
// The resolved contact is provided to the contactComponent's contact binding
contact: ($transition$) => ContactsStorage.get($transition$.params().contactId)
},
component: ContactView
};
/**
* This state allows a user to edit a contact
*
* The contact data to edit is injected from the parent state's resolve.
*
* This state uses view targeting to replace the parent ui-view (which would normally be filled
* by 'contacts.contact') with the edit contact template/controller
*/
const editContactState = {
name: 'contacts.contact.edit',
url: '/edit',
views: {
// Relatively target the grand-parent-state's $default (unnamed) ui-view
// This could also have been written using ui-view@state addressing: $default@contacts
// Or, this could also have been written using absolute ui-view addressing: !$default.$default.$default
'^.^.$default': {
//bindings: { pristineContact: "contact" },
component: EditContact
}
}
};
/**
* This state allows a user to create a new contact
*
* The contact data to edit is injected into the component from the parent state's resolve.
*/
const newContactState = {
name: 'contacts.new',
url: '/new',
component: EditContact
};
export const states = [contactsState, viewContactState, editContactState, newContactState];