Comments (2)
Yeah, I was thinking about it while working on the redux implementation. It would be great to have the method inside the core and then extend form that if needed.
We should define what the plugin should export, in order to create consistency between plugins and to provide .plugin()
implementation that works independently.
naive example:
export function myAwesomePlugin (routerInstance) {
// do something with the router instance
}
so .plugin()
could be:
// inside the UIRouter class
plugin = (pluginToApply) => {
pluginToApply(this);
}
from core.
@elboman
This is what I'm thinking:
/**
* Adds a plugin to UI-Router
*
* This method adds a UI-Router Plugin.
* A plugin can enhance or change UI-Router behavior using any public API.
*
* #### Example:
* ```js
* import { MyCoolPlugin } from "ui-router-cool-plugin";
*
* var plugin = router.addPlugin(MyCoolPlugin);
* ```
*
* ### Plugin authoring
*
* A plugin is simply a class (or constructor function) which accepts a [[UIRouter]] instance and (optionally) an options object.
*
* The plugin can implement its functionality using any of the public APIs of [[UIRouter]].
* For example, it may configure router options or add a Transition Hook.
*
* The plugin can then be published as a separate module.
*
* #### Example:
* ```js
* export class MyAuthPlugin {
* constructor(router: UIRouter, options: any) {
* let $transitions = router.transitionService;
* let $state = router.stateService;
*
* let authCriteria = {
* to: (state) => state.data && state.data.requiresAuth
* };
*
* function authHook(transition: Transition) {
* let authService = transition.injector().get('AuthService');
* if (!authService.isAuthenticated()) {
* return $state.target('login');
* }
* }
*
* $transitions.onStart(authCriteria, authHook);
* }
* }
* ```
*
* @param PluginClass a UI-Router Plugin class (or constructor function).
* @param options options to pass to the plugin
* @returns {T}
*/
addPlugin<T extends UIRouterPlugin>(PluginClass: { new(router: UIRouter, options?: any): T }, options: any = {}): T {
let pluginInstance = new PluginClass(this, options);
var pluginName = pluginInstance.name();
return this._plugins[pluginName] = pluginInstance;
}
from core.
Related Issues (20)
- License clash MIT vs CC BY-SA 3.0 HOT 2
- @uirouter/react 0.8.9 not finding UIRouter HOT 1
- Any plan for Svelte 3? HOT 7
- Can't compile angular 8 under typescript "~3.5.3" HOT 3
- Version 6.0.2 breaks using ui-router core on Node.js without a browser HOT 1
- Can't bootstrap a hybrid application in Angular 8 due to commonservices being undefined HOT 6
- string parameters are url encoding issue HOT 5
- is AOT supported? HOT 1
- Ability to set defaultHrefOpts globally HOT 3
- Ugrading to uirouter1.x and installed ui-router-core and ui-router-angularjs ,doesnt support legacy code base HOT 1
- `inherit` is documented as having the wrong default value HOT 1
- Cannot read property 'when' of undefined HOT 19
- Child states their childs, show the parent component HOT 3
- Set uiOptions.reload of [uiSref] to a future load state name lead to error at first load HOT 1
- license issue HOT 1
- How to lazy load with chunks HOT 1
- Support Ivy partial compilation HOT 10
- `ParamDeclaration.inherit = false` is ignored by `$state.href()`
- Issue with StateParams HOT 4
- error TS1086: An accessor cannot be declared in an ambient context (v6.1.1) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.