Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { memoize } from '@app/decorators/memoize'
- export class MyComponent {
- @memoize()
- private static memoizeEyeSrc(clickCount, maxEyeClickCount, botEyesDir) {
- return clickCount < maxEyeClickCount ? botEyesDir + '/bot-eye-tiny.png' : botEyesDir + '/bot-eye-black-tiny.png'
- }
- get leftEyeSrc() {
- return MyComponent.memoizeEyeSrc(this.eyes.left.clickCount, this.maxEyeClickCount, this.botEyesDir)
- }
- }
- // decorated method must be pure
- import * as memoizee from 'memoizee'
- export const memoize = (): MethodDecorator => {
- return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
- const func = descriptor.value
- descriptor.value = memoizee(func)
- return descriptor
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement