MCPcopy
hub / github.com/thinkjs/thinkjs / action

Function action

lib/extend/controller.js:270–292  ·  view source on GitHub ↗

* execute action * @param {String} controller * @param {String} actionName * @param {String} m

(controller, actionName, m)

Source from the content-addressed store, hash-verified

268 * @param {String} m
269 */
270 action(controller, actionName, m) {
271 let instance = controller;
272 // if controller is an controller instance, ignore invoke controller method
273 if (helper.isString(controller)) {
274 instance = this.controller(controller, m);
275 }
276 let promise = Promise.resolve();
277 if (instance.__before) {
278 promise = Promise.resolve(instance.__before());
279 }
280 return promise.then(data => {
281 if (data === false) return false;
282 let method = `${actionName}Action`;
283 if (!instance[method]) {
284 method = '__call';
285 }
286 if (instance[method]) return instance[method]();
287 }).then(data => {
288 if (data === false) return false;
289 if (instance.__after) return instance.__after();
290 return data;
291 });
292 },
293 /**
294 * download
295 * @param {String} filepath

Callers

nothing calls this directly

Calls 3

controllerMethod · 0.80
__beforeMethod · 0.80
__afterMethod · 0.80

Tested by

no test coverage detected