5.10.7 • Published 3 months ago

yeux v5.10.7

Weekly downloads
6
License
MPL-2.0
Repository
github
Last release
3 months ago

Yeux

build status code coverage license

Yeux improves the performance of applications that create many light-weight and short-lived objects.

import { yeux } from 'yeux'

interface Player {
  name: string | undefined
  x: number
  y: number
}

interface PlayerInitial extends Player {
  name: undefined
  x: 0
  y: 0
}

const pool = yeux<Player, PlayerInitial>(
  () => ({
    name: undefined,
    x: 0,
    y: 0
  }),
  obj => {
    obj.x = 0
    obj.y = 0
    obj.name = undefined

    return obj as PlayerInitial
  }
)

const A = pool.get()
const B = pool.get()

pool.pool(A, B)

const C = pool.get()
const D = pool.get()

A === C // true
B === D // true

API

yeux

yeux function takes two arguments and two type arguments and returns the pool, get, and isActive methods. The first type argument is the wider object type (Player in the example). The second type argument is a narrowed down, initial object type (PlayerInitial in the example). The first argument is an object factory function, and the second argument is a reset function.

get

get function returns an object from a pool, or if the pool is empty calls the factory function and returns the object. The objects returned by the factory function are not placed in the pool so that they can be disposed of by the garbage collector.

pool

Objects are placed back in the pool with the pool function. Objects not placed back in the pool are disposed of by the garbage collector no references to them exist.

isPooled

The isPooled function receives an object as an argument and returns true if the object is present in the pool, and returns false if the object is not present.

License

MPL-2.0

5.10.7

3 months ago

5.10.6

6 months ago

5.10.5

6 months ago

5.5.0

11 months ago

5.3.1

11 months ago

5.3.0

11 months ago

5.8.0

10 months ago

5.6.0

11 months ago

5.2.3

11 months ago

5.4.0

11 months ago

5.2.2

11 months ago

5.2.1

11 months ago

5.10.4

7 months ago

5.10.3

8 months ago

5.10.1

9 months ago

5.10.0

10 months ago

5.9.3

10 months ago

5.9.2

10 months ago

5.9.1

10 months ago

5.9.0

10 months ago

5.7.2

10 months ago

5.7.1

11 months ago

5.7.0

11 months ago

5.2.0

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.0

1 year ago

4.1.7

1 year ago

4.1.4

1 year ago

4.1.3

1 year ago

4.1.6

1 year ago

4.1.5

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.1.2

1 year ago

4.1.1

1 year ago

3.2.0

1 year ago

2.4.1

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

3.0.2

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.4.0

2 years ago

2.2.1

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.2.2

2 years ago

2.3.4

2 years ago

2.3.3

2 years ago

1.0.1

6 years ago

1.0.0

6 years ago