-
## Functions
@@ -96,45 +92,17 @@ Function's name start or end with "_" will not be able to apply middleware.
**Kind**: global class
* [MiddlewareManager](#MiddlewareManager)
- * [new MiddlewareManager(target, ...middlewareObjects)](#new_MiddlewareManager_new)
+ * [.MiddlewareManager](#MiddlewareManager+MiddlewareManager)
+ * [new exports.MiddlewareManager(target, ...middlewareObjects)](#new_MiddlewareManager+MiddlewareManager_new)
* [.use(methodName, ...middlewares)](#MiddlewareManager+use) ⇒ object
-
-
-### new MiddlewareManager(target, ...middlewareObjects)
-**Returns**: object - this
-
-| Param | Type | Description |
-| --- | --- | --- |
-| target | object | The target object. |
-| ...middlewareObjects | object | Middleware objects. |
-
-
-
-### middlewareManager.use(methodName, ...middlewares) ⇒ object
-Apply (register) middleware functions to the target function or apply (register) middleware objects.
-If the first argument is a middleware object, the rest arguments must be middleware objects.
-
-**Kind**: instance method of [MiddlewareManager](#MiddlewareManager)
-**Returns**: object - this
-
-| Param | Type | Description |
-| --- | --- | --- |
-| methodName | string | object | String for target function name, object for a middleware object. |
-| ...middlewares | function | object | The middleware chain to be applied. |
-
-
-
-## MiddlewareManager
-**Kind**: global class
-
-* [MiddlewareManager](#MiddlewareManager)
- * [new MiddlewareManager(target, ...middlewareObjects)](#new_MiddlewareManager_new)
- * [.use(methodName, ...middlewares)](#MiddlewareManager+use) ⇒ object
+
-
+### middlewareManager.MiddlewareManager
+**Kind**: instance class of [MiddlewareManager](#MiddlewareManager)
+
-### new MiddlewareManager(target, ...middlewareObjects)
+#### new exports.MiddlewareManager(target, ...middlewareObjects)
**Returns**: object - this
| Param | Type | Description |
@@ -148,13 +116,13 @@ If the first argument is a middleware object, the rest arguments must be middlew
Apply (register) middleware functions to the target function or apply (register) middleware objects.
If the first argument is a middleware object, the rest arguments must be middleware objects.
-**Kind**: instance method of [MiddlewareManager](#MiddlewareManager)
+**Kind**: instance method of [MiddlewareManager](#MiddlewareManager)
**Returns**: object - this
| Param | Type | Description |
| --- | --- | --- |
-| methodName | string | object | String for target function name, object for a middleware object. |
-| ...middlewares | function | object | The middleware chain to be applied. |
+| methodName | string \| object | String for target function name, object for a middleware object. |
+| ...middlewares | function \| object | The middleware chain to be applied. |
diff --git a/docs/html/MiddlewareManager.html b/docs/html/MiddlewareManager.html
index ac85a12..a593927 100644
--- a/docs/html/MiddlewareManager.html
+++ b/docs/html/MiddlewareManager.html
@@ -33,7 +33,7 @@
it must call next() to pass control to the next middleware function. Otherwise,
the target function will be left hanging.
e.g.
-
const walk = target => next => (...args) => {
- this.log(`walk function start.`);
- const result = next(...args);
- this.log(`walk function end.`);
- return result;
- }
Middleware object is an object that contains function's name as same as the target object's function name.
+
const walk = target => next => (...args) => {
+ this.log(`walk function start.`);
+ const result = next(...args);
+ this.log(`walk function end.`);
+ return result;
+ }
+
+
Middleware object is an object that contains function's name as same as the target object's function name.
e.g.
-
const Logger = {
- walk: target => next => (...args) => {
- console.log(`walk function start.`);
- const result = next(...args);
- console.log(`walk function end.`);
- return result;
- }
- }
Function's name start or end with "_" will not be able to apply middleware.
+
const Logger = {
+ walk: target => next => (...args) => {
+ console.log(`walk function start.`);
+ const result = next(...args);
+ console.log(`walk function end.`);
+ return result;
+ }
+ }
+
+
Function's name start or end with "_" will not be able to apply middleware.
@@ -302,451 +306,17 @@
Example
-
-
-
-
-
-
-
-
-
Methods
+
Classes
-
-
-
-
use(methodName, middlewares)
-
-
-
-
-
-
-
-
Apply (register) middleware functions to the target function or apply (register) middleware objects.
-If the first argument is a middleware object, the rest arguments must be middleware objects.
-
-
-
-
-
-
-
-
-
-
Parameters:
-
-
-
-
-
-
-
Name
-
-
-
Type
-
-
-
Argument
-
-
-
-
-
Description
-
-
-
-
-
-
-
-
-
methodName
-
-
-
-
-
-string
-|
-
-object
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
String for target function name, object for a middleware object.
Powerful Javascript Middleware Pattern implementation, apply middleweares to any object.
+
js-middleware
+
Powerful Javascript Middleware Pattern implementation, apply middleweares to any object.
A painless solution to make codes as scalable and maintainable as ReduxJS and ExpressJS.
Middleware functions are functions that have access to the target function and it's arguments,
+
Overview
+
Middleware functions are functions that have access to the target function and it's arguments,
and the target object and the next middleware function in the target function cycle.
The next middleware function is commonly denoted by a variable named next.
Middleware functions can perform the following tasks:
@@ -108,42 +111,60 @@
Overview
Middleware functions are functions that have access to the t
Execute any code.
Make changes to the function's arguments.
End the target function.
-
Call the next middleware in the stack.
+
Call the next middleware in the stack.
+
If the current middleware function does not end the target function cycle,
it must call next() to pass control to the next middleware function. Otherwise,
the target function will be left hanging.
-
-
-
Get started
+
Get started
+
window.MiddlewareManager is available for browsers by include
-dist/middleware.min.js file in your HTML.
import {MiddlewareManager} from 'js-middleware';
+
+
Usages
+
Basic
+
We define a Person class.
// the target object
class Person {
// the target function
walk(step) {
this.step = step;
}
-
+
speak(word) {
this.word = word;
}
- }
Then we define a middleware function to print log.
+ }
+
+
Then we define a middleware function to print log.
// middleware for walk function
const logger = target => next => (...args) => {
console.log(`walk start, steps: ${args[0]}.`);
const result = next(...args);
console.log(`walk end.`);
return result;
- }
Now we apply the log function as a middleware to a Person instance.
+ }
+
+
Now we apply the log function as a middleware to a Person instance.
// apply middleware to target object
const p = new Person();
const middlewareManager = new MiddlewareManager(p);
middlewareManager.use('walk', logger);
- p.walk(3);
Whenever a Person instance call it's walk method, we'll see logs from the looger middleware.
-
Middleware object
We can also apply a middleware object to a target object. Middleware object is an object that contains function's name as same as the target object's function name.
+ p.walk(3);
+
+
Whenever a Person instance call it's walk method, we'll see logs from the looger middleware.
+
Middleware object
+
We can also apply a middleware object to a target object. Middleware object is an object that contains function's name as same as the target object's function name.
Function's name start or end with "_" will not be able to apply middleware.
We can also apply a middleware object to a target o
const middlewareManager = new MiddlewareManager(p);
middlewareManager.use(PersonMiddleware);
p.walk(3);
- p.speak('hi');
middlewareMethods
In a class, function's name start or end with "_" will not be able to apply as middleware.
+ p.speak('hi');
+
+
middlewareMethods
+
In a class, function's name start or end with "_" will not be able to apply as middleware.
Or we can use middlewareMethods to define function names for middleware target within a class.
class PersonMiddleware {
constructor() {
@@ -201,40 +225,52 @@
Middleware object
We can also apply a middleware object to a target o
const middlewareManager = new MiddlewareManager(p);
middlewareManager.use(new PersonMiddleware())
p.walk(3);
- p.speak('hi');
APIs
.use(methodName, ...middlewares)
Apply (register) middleware functions to the target function or apply (register) middleware objects.
+ p.speak('hi');
+
+
APIs
+
.use(methodName, ...middlewares)
+
Apply (register) middleware functions to the target function or apply (register) middleware objects.
If the first argument is a middleware object, the rest arguments must be middleware objects.
{string|object} methodName String for target function name, object for a middleware object.
{...function} middlewares The middleware chain to be applied.
return {object} this
-
Build
-
Run npm install to install requirements.
+
Build
+
+
+
Run npm install to install requirements.
-
Run gulp to builds the library, generates dist/middleware.js as the core script, watches for file changes,
+
+
Run gulp to builds the library, generates dist/middleware.js as the core script, watches for file changes,
starts a HTTP server for debug.
+
+
Usage
- gulp [TASK] [OPTIONS...]
+ gulp [TASK] [OPTIONS...]
Available tasks
- build Builds the library.
- clean Cleans files.
- clean:dist Cleans dist files.
- clean:docs Cleans docs files.
- default
- docs Builds documentation.
- docs:html Builds HTML documentation.
- docs:md Builds markdown documentation.
- help Display this help text.
- lint Lint JS files.
- mini Minify the library.
- server Starts a HTTP server for debug.
- test Run test cases.
- watch Watches for changes in files, re-lint, re-build & re-docs.
-
Run gulp docs to build docs. View markdown docs with docs/API.md, or run gulp server to start a HTTP server
+ build Builds the library.
+ clean Cleans files.
+ clean:dist Cleans dist files.
+ clean:docs Cleans docs files.
+ default
+ docs Builds documentation.
+ docs:html Builds HTML documentation.
+ docs:md Builds markdown documentation.
+ help Display this help text.
+ lint Lint JS files.
+ mini Minify the library.
+ server Starts a HTTP server for debug.
+ test Run test cases.
+ watch Watches for changes in files, re-lint, re-build & re-docs.
+
+
+
Run gulp docs to build docs. View markdown docs with docs/API.md, or run gulp server to start a HTTP server
and view HTML docs with localhost:3000/docs/html/.
-
Roadmap & Make contributions
+
Roadmap & Make contributions
+
Supports RegExp to match method names, pass the current method name as param to the current middleware.
once(methodName, ...middlewares) Apply middlewares only run once.
Be able to unuse middlewares.
@@ -282,9 +318,9 @@
Search results
- Documentation generated by JSDoc 3.4.3
+ Documentation generated by JSDoc 3.6.3
- on 2017-06-21
+ on 2020-02-10
using the DocStrap template.
diff --git a/docs/html/quicksearch.html b/docs/html/quicksearch.html
index 204fd74..54586f8 100644
--- a/docs/html/quicksearch.html
+++ b/docs/html/quicksearch.html
@@ -7,7 +7,7 @@