Javascript commons
npm i @hydre/commons
Execute a promise outside scope
import { Deferred } from '@hydre/commons'
const def = new Deferred()
def.promise.then(console.log('slt'))
setTimeout(() => {
def.resolve() // or deferred.reject()
}, 1000)
Call the function/getter only once and keep the result in memory
import { cache } from '@hydre/commons'
class Foo {
@cache
bar() {
console.log('This line will be printed only once')
return new myApiCall()
}
@cache
get baz() {
return 5 + 5
}
}
Multiple class inheritance see exploring-es7-decorators
import { mixin } from '@hydre/commons'
const TimeStone = mixin({
get canRewind() {
return true
}
})
const PlaysFortnite = mixin({
isDumb() {
return true
}
})
@TimeStone
@PlaysFortnite
class Thanos {
isDumb() {
return false
}
}
new Thanos().isDumb() |> console.log // print true