1.2.8 • Published 6 years ago

@gallink/oxygen v1.2.8

Weekly downloads
16
License
MIT
Repository
github
Last release
6 years ago

Oxygen brings life to other Gallink applications by providing a set of useful utilities.

Using Queues

Queues are a neat approach to processing a collection of items. Both of the implementations have different purposes, both which are particularly useful.

First is the standard Queue implementation, which is simply a box for an Array with the ability to dequeue items in a controlled, FIFO respect.

const friendsToAdd: Queue<Friend> = new Queue(api.getFriendSuggestions())

while (friendsToAdd.pending) {
    
    const friendToAdd: Friend = friendsToAdd.dequeue();
    
    await friendToAdd.sendFriendRequest() 
    
}

// Friends added!

PromiseQueue adds another layer of asynchronous debuffing to JavaScript by allowing you to queue Promises. We can rewrite the sample above to use these.

const friendsToAdd: Queue<Friend> = new Queue(api.getFriendSuggestions())
const friendsBeingAded: PromiseQueue<Friend> = new PromiseQueue<Friend>();

while (friendsToAdd.pending) {
    
    const friendToAdd: Friend = friendsToAdd.dequeue();
    
    await friendsBeingAdded.task(friendToAdd.sendFriendRequestAsync)
    
}

The difference between these two examples is that the first will handle all the friend requests at once, whereas the second example will handle one at a time.

Create Handleable Actions

Inspired by Node's EventEmitter, Actionable provides an attractive alternative to calling code in other places by firing actions that are listened to elsewhere - a professional use for callbacks.

const me: Person = new Person("Crowes");

me.on("hungry", me.eat())

Genuine Data Models

JavaScript does a poor job of supporting genuine data models, leaving you to write a lot of the boilerplate for a lot of your reflection-style work which is so commonly required in typical JavaScript applications.

const me: Person = new Person("Crowes", 21);
const differentMe: Person = new Person("Crowes", 22);

const difference: Map<string, any> = me.difference();
// { "age", 22 }
1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

0.7.1

7 years ago

1.0.0

7 years ago