new package: burns

This commit is contained in:
timolinn
2019-03-26 17:02:08 +01:00
parent afea35d9ff
commit 2474134ef0
4 changed files with 80 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import burns from 'burns';
interface OrderData {
userName: string;
orderId: string;
}
function handleEverything() {
console.log('Do absolutely nothing! 😄');
}
function sendEmail(message: string) {
console.log(message);
}
function sendOrderShippedEmail(data: OrderData) {
sendEmail(`Hi ${data.userName}, Your order ${data.orderId} has been shipped`);
}
burns.configure({
defaultHandler: handleEverything
});
burns.registerEvents({
newPurchase: sendOrderShippedEmail
});
burns.dispatch('newPurchase', {
userName: 'Johnny',
orderId: 'rand'
});
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for burns version 2.0.1
// Project: https://github.com/shalvah/burns
// Definitions by: Timothy Onyiuke <https://github.com/timolinn>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare const _Burns: Burns;
export interface Config {
defaultHandler?: any;
broadcaster?: any;
pusher?: any;
}
export interface ObjectLiteral {
[key: string]: any
}
declare class Burns {
configure(config?: Config): this;
registerEvents(newEvents: ObjectLiteral): this;
dispatch(eventName: string, eventData?: ObjectLiteral, exclude?: { exclude?: any }): this;
}
export default _Burns;
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"burns-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }