JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q69266F
  • License MIT

You need some milk ?

Package Exports

  • @hydre/commons

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hydre/commons) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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