Last active
July 16, 2020 00:19
-
-
Save yoSteve/9a2ec7b392d91cc61ebd2bc916a37087 to your computer and use it in GitHub Desktop.
DevLog: A Most Excellent Custom RxJS Operator
This file contains hidden or 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
import { tap } from 'rxjs/operators'; | |
import { environment as ENV } from '../../environments/environment'; // NOTE: adjust path to environment files | |
const normalStyle = [ | |
'display: block', | |
'color: mediumVioletRed', | |
'font-weight: normal', | |
'background: linear-gradient(135deg, #98fb98 66%, #22c1c3 100%)', | |
'padding: 3px 9px', | |
].join(';'); | |
const errorStyle = [ | |
'display: block', | |
'color: #512500', | |
'font-weight: normal', | |
'background: linear-gradient(135deg, #f87666 55%, #ff934f 100%)', | |
'padding: 3px 9px', | |
].join(';'); | |
const completeStyle = [ | |
'display: block', | |
'color: #2f3061', | |
'font-weight: normal', | |
'background: linear-gradient(135deg, #22c1c3 66%, #50723c 100%)', | |
'padding: 3px 9px', | |
].join(';'); | |
export function devlog(message: string) { | |
return tap({ | |
next(val) { | |
if (!ENV.production) { | |
if (typeof val === 'string') { | |
console.log(`%c${message}: ${val ? val : '📭 (empty string)'}`, normalStyle); | |
} else if (typeof val === 'number' || typeof val === 'boolean') { | |
console.log(`%c${message}: ${val}`, normalStyle); | |
} else { | |
console.log(`%c${message}: %O`, normalStyle, val); | |
} | |
} | |
}, | |
error(error) { | |
if (!ENV.production) { | |
console.log(`☠️ ERROR: %c${message}: %O`, errorStyle, error); | |
} | |
}, | |
complete() { | |
if (!ENV.production) { | |
console.log(`%c${message}: Complete`, completeStyle); | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use: