1.0.22 • Published 4 years ago

@hydre/commons v1.0.22

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@hydre/commons

Javascript commons

Install

npm i @hydre/commons

Use:

Deferred Promise

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)

Decorators

@cache

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
	}
}

Helpers

mixin

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
1.0.22

4 years ago

1.0.20

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago