Skip to content

Commit cf1a801

Browse files
0x-r4bbitmfield
authored andcommitted
docs(state): wip documentation for state service
1 parent 7bf1d5d commit cf1a801

File tree

1 file changed

+128
-2
lines changed

1 file changed

+128
-2
lines changed

src/state.js

+128-2
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,85 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
335335
return this;
336336
}
337337

338-
// .state(state)
339-
// .state(name, state)
338+
/**
339+
* @ngdoc function
340+
* @name ui.router.state.$stateProvider#state
341+
* @methodOf ui.router.state.$stateProvider
342+
*
343+
* @description
344+
* Registers a state configuration under a given state name. The stateConfig object
345+
* has the following acceptable properties.
346+
*
347+
* - [`template`, `templateUrl`, `templateProvider`] - There are three ways to setup
348+
* your templates.
349+
*
350+
* - `{string|object}` - template - String HTML content, or function that returns an HTML
351+
* string.
352+
* - `{string}` - templateUrl - String URL path to template file OR function,
353+
* that returns URL path string.
354+
* - `{object}` - templateProvider - Provider function that returns HTML content
355+
* string.
356+
*
357+
* - [`controller`, `controllerProvider`] - A controller paired to the state. You can
358+
* either use a controller, or a controller provider.
359+
*
360+
* - `{string|object}` - controller - Controller function or controller name.
361+
* - `{object}` - controllerProvider - Injectable provider function that returns
362+
* the actual controller or string.
363+
*
364+
* - `{object}` - resolve - A map of dependencies which should be injected into the
365+
* controller.
366+
*
367+
* - `{string}` - url - A url with optional parameters. When a state is navigated or
368+
* transitioned to, the `$stateParams` service will be populated with any
369+
* parameters that were passed.
370+
*
371+
* - `{object}` - params - An array of parameter names or regular expressions. Only
372+
* use this within a state if you are not using url. Otherwise you can specify your
373+
* parameters within the url. When a state is navigated or transitioned to, the
374+
* $stateParams service will be populated with any parameters that were passed.
375+
*
376+
* - `{object}` - views - Use the views property to set up multiple views.
377+
* If you don't need multiple views within a single state this property is not
378+
* needed. Tip: remember that often nested views are more useful and powerful
379+
* than multiple sibling views.
380+
*
381+
* - `{boolean}` - abstract - An abstract state will never be directly activated,
382+
* but can provide inherited properties to its common children states.
383+
*
384+
* - `{object}` - onEnter - Callback function for when a state is entered. Good way
385+
* to trigger an action or dispatch an event, such as opening a dialog.
386+
*
387+
* - `{object}` - onExit - Callback function for when a state is exited. Good way to
388+
* trigger an action or dispatch an event, such as opening a dialog.
389+
*
390+
* - `{object}` - data - Arbitrary data object, useful for custom configuration.
391+
*
392+
* @example
393+
* <pre>
394+
* // The state() method takes a unique stateName (String) and a stateConfig (Object)
395+
* $stateProvider.state(stateName, stateConfig);
396+
*
397+
* // stateName can be a single top-level name (must be unique).
398+
* $stateProvider.state("home", {});
399+
*
400+
* // Or it can be a nested state name. This state is a child of the above "home" state.
401+
* $stateProvider.state("home.newest", {});
402+
*
403+
* // Nest states as deeply as needed.
404+
* $stateProvider.state("home.newest.abc.xyz.inception", {});
405+
*
406+
* // state() returns $stateProvider, so you can chain state declarations.
407+
* $stateProvider
408+
* .state("home", {})
409+
* .state("about", {})
410+
* .state("contacts", {});
411+
* </pre>
412+
*
413+
* @param {string} name A unique state name, e.g. "home", "about", "contacts".
414+
* To create a parent/child state use a dot, e.g. "about.sales", "home.newest".
415+
* @param {object} definition State configuratino object.
416+
*/
340417
this.state = state;
341418
function state(name, definition) {
342419
/*jshint validthis: true */
@@ -346,6 +423,29 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
346423
return this;
347424
}
348425

426+
/**
427+
* @ngdoc object
428+
* @name ui.router.state.$state
429+
*
430+
* @requires $rootScope
431+
* @requires $q
432+
* @requires ui.router.state.$view
433+
* @requires $injector
434+
* @requires ui.router.util.$resolve
435+
* @requires ui.router.state.$stateParams
436+
*
437+
* @property {object} params A param object, e.g. {sectionId: section.id)}, that
438+
* you'd like to test against the current active state.
439+
* @property {object} current A reference to the state's config object. However
440+
* you passed it in. Useful for accessing custom data.
441+
* @property {object} transition Currently pending transition. A promise that'll
442+
* resolve or reject.
443+
*
444+
* @description
445+
* `$state` service is responsible for representing states as well as transitioning
446+
* between them. It also provides interfaces to ask for current state or even states
447+
* you're coming from.
448+
*/
349449
// $urlRouter is injected just to ensure it gets instantiated
350450
this.$get = $get;
351451
$get.$inject = ['$rootScope', '$q', '$view', '$injector', '$resolve', '$stateParams', '$location', '$urlRouter'];
@@ -372,10 +472,36 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
372472
transition: null
373473
};
374474

475+
/**
476+
* @ngdoc function
477+
* @name ui.router.state.$state#reload
478+
* @methodOf ui.router.state.$state
479+
*
480+
* @description
481+
* Reloads the current state by re-transitioning to it.
482+
*/
375483
$state.reload = function reload() {
376484
$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false });
377485
};
378486

487+
/**
488+
* @ngdoc function
489+
* @name ui.router.state.$state#go
490+
* @methodOf ui.router.state.$state
491+
*
492+
* @description
493+
* Convenience method for transitioning to a new state. `$state.go` calls
494+
* `$state.transitionTo` internally but automatically sets options to
495+
* `{ location: true, inherit: true, relative: $state.$current, notify: true }`.
496+
* This allows you to easily use an absolute or relative to path and specify
497+
* only the parameters you'd like to update (while letting unspecified parameters
498+
* inherit from the current state.
499+
*
500+
* @param {string} to Absolute State Name or Relative State Path.
501+
* @param {object} params A map of the parameters that will be sent to the state,
502+
* will populate $stateParams.
503+
* @param {object} options If Object is passed, object is an options hash.
504+
*/
379505
$state.go = function go(to, params, options) {
380506
return this.transitionTo(to, params, extend({ inherit: true, relative: $state.$current }, options));
381507
};

0 commit comments

Comments
 (0)