Last active
November 17, 2015 10:00
-
-
Save mdix/7e1b7358eff5f7ce21eb to your computer and use it in GitHub Desktop.
Interface check for stampit 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var stampit = require('stampit'); | |
const MyInterfaceCheckStamp = | |
stampit() | |
.init(function(stamp) { | |
for (var method in stamp.stamp.fixed.methods) { | |
var currentMethod = stamp.stamp.fixed.methods[method]; | |
if (currentMethod.toString().match(/{[\s\n]*}/g) !== null) { | |
throw new Error('Method \’' + method.toString() + '\' needs to be implemented.'); | |
} | |
} | |
}) | |
const MyInterfaceStamp = | |
stampit() | |
.compose(MyInterfaceCheckStamp) | |
.methods( | |
{ | |
connect: () => {}, | |
save: function() {} | |
} | |
) | |
const MyImplementationStamp = | |
stampit() | |
.compose(MyInterfaceStamp) | |
.methods( | |
{ | |
connect: () => { | |
// implementation | |
} | |
} | |
) | |
var myImplementationStamp = MyImplementationStamp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment