@javish/lib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +29 -0
  2. package/package.json +8 -0
package/index.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A factory that creates an implementation from a given inline class and
3
+ * additional methods supplied as a record.
4
+ *
5
+ * ```js
6
+ * var ListenerImpl = ImplFactory
7
+ *
8
+ * // then,
9
+ * var listener = new (ListenerImpl(class MyListener {
10
+ * parts = [] // initial fields
11
+ * }, {
12
+ * onText(webSocket, message, last) {
13
+ * // custom implementation.
14
+ * }
15
+ * }))
16
+ * ```
17
+ * @param {Function} Base
18
+ * @param {Record<string,Function>} methods
19
+ */
20
+ var ImplFactory=function(Base,methods){
21
+ return function(){
22
+ var obj=new Base
23
+ var proto=Object.getPrototypeOf(obj)
24
+ for(var k in methods) proto[k]=methods[k]
25
+ return obj
26
+ }
27
+ }
28
+
29
+ module.exports.ImplFactory=ImplFactory
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@javish/lib",
3
+ "version": "0.1.0",
4
+ "author": {
5
+ "name": "British Software",
6
+ "email": "packages+javish@british.software"
7
+ }
8
+ }