项目原始demo,不改动
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Tapable
  2. ``` javascript
  3. var Tapable = require("tapable");
  4. ```
  5. `Tapable` is a class for plugin binding and applying.
  6. Just extend it.
  7. ``` javascript
  8. function MyClass() {
  9. Tapable.call(this);
  10. }
  11. MyClass.prototype = Object.create(Tapable.prototype);
  12. MyClass.prototype.method = function() {};
  13. ```
  14. Or mix it in.
  15. ``` javascript
  16. function MyClass2() {
  17. EventEmitter.call(this);
  18. Tapable.call(this);
  19. }
  20. MyClass2.prototype = Object.create(EventEmitter.prototype);
  21. Tapable.mixin(MyClass2.prototype);
  22. MyClass2.prototype.method = function() {};
  23. ```
  24. ## Public functions
  25. ### apply
  26. ``` javascript
  27. void apply(plugins: Plugin...)
  28. ```
  29. Attaches all plugins passed as arguments to the instance, by calling `apply` on them.
  30. ### plugin
  31. ``` javascript
  32. void plugin(names: string|string[], handler: Function)
  33. ```
  34. `names` are the names (or a single name) of the plugin interfaces the class provides.
  35. `handler` is a callback function. The signature depends on the class. `this` is the instance of the class.
  36. ## Protected functions
  37. ### applyPlugins
  38. ``` javascript
  39. void applyPlugins(name: string, args: any...)
  40. ```
  41. Synchronously applies all registered handlers for `name`. The handler functions are called with all args.
  42. ### applyPluginsWaterfall
  43. ``` javascript
  44. any applyPluginsWaterfall(name: string, init: any, args: any...)
  45. ```
  46. Synchronously applies all registered handlers for `name`. The handler functions are called with the return value of the previous handler and all args. For the first handler `init` is used and the return value of the last handler is return by `applyPluginsWaterfall`
  47. ### applyPluginsAsync
  48. ``` javascript
  49. void applyPluginsAsync(
  50. name: string,
  51. args: any...,
  52. callback: (err?: Error) -> void
  53. )
  54. ```
  55. Asynchronously applies all registered handlers for `name`. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The handler functions are called in order of registration.
  56. `callback` is called after all handlers are called.
  57. ### applyPluginsBailResult
  58. ``` javascript
  59. any applyPluginsBailResult(name: string, args: any...)
  60. ```
  61. Synchronously applies all registered handlers for `name`. The handler function are called with all args. If a handler function returns something `!== undefined`, the value is returned and no more handlers are applied.
  62. ### applyPluginsAsyncWaterfall
  63. ``` javascript
  64. applyPluginsAsyncWaterfall(
  65. name: string,
  66. init: any,
  67. callback: (err: Error, result: any) -> void
  68. )
  69. ```
  70. Asynchronously applies all registered handlers for `name`. The handler functions are called with the current value and a callback function with the signature `(err: Error, nextValue: any) -> void`. When called, `nextValue` is the current value for the next handler. The current value for the first handler is `init`. After all handlers are applied, `callback` is called with the last value. If any handler passes a value for `err`, the `callback` is called with this error and no more handlers are called.
  71. ### applyPluginsAsyncSeries
  72. ``` javascript
  73. applyPluginsAsyncSeries(
  74. name: string,
  75. args: any...,
  76. callback: (err: Error, result: any) -> void
  77. )
  78. ```
  79. Asynchronously applies all registered handlers for `name`. The handler functions are called with all `args` and a callback function with the signature `(err: Error) -> void`. The handlers are called in series, one at a time. After all handlers are applied, `callback` is called. If any handler passes a value for `err`, the `callback` is called with this error and no more handlers are called.
  80. ### applyPluginsParallel
  81. ``` javascript
  82. applyPluginsParallel(
  83. name: string,
  84. args: any...,
  85. callback: (err?: Error) -> void
  86. )
  87. ```
  88. Applies all registered handlers for `name` in parallel. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The `callback` function is called when all handlers have called the callback without `err`. If any handler calls the callback with `err`, `callback` is invoked with this error and the other handlers are ignored.
  89. ### applyPluginsParallelBailResult
  90. ``` javascript
  91. applyPluginsParallelBailResult(
  92. name: string,
  93. args: any...,
  94. callback: (err: Error, result: any) -> void
  95. )
  96. ```
  97. Applies all registered handlers for `name` in parallel. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. Handler functions must call the callback. They can either pass an error, pass undefined, or pass a value. The first result (either error or value) which is not undefined is passed to the `callback`. The order is defined by registration, not by the speed of the handler function.
  98. ### hasPlugins
  99. ``` js
  100. hasPlugins(
  101. name: string
  102. )
  103. ```
  104. Returns true, if plugins are registered for this name.