Git Product home page Git Product logo

turbine-jobscheduler's Introduction

eyepatch

A library of notification based objects

Installation

npm install eyepatch --save

Why?

Sometimes you just want to know when something happens without the need of checking it yourself. You just want to be notified when the change happens.

Who?

Just me myself and I, in my free time

Features

  • Events - Simple or parametrized.
  • ConditionalEvent - Simple or parametrized.
  • GlobalEvent - To broadcast events globally
  • ObservableCollection - notifies you when something changes.
  • ObservableDictionary - Works with keys as an object and not only strings and numbers. Notifies on changes. Works simply adding non enumerable property as the key id. This doesn't affect the JSON.stringify method nor the for in loop.

Languages

The library is written in TypeScript but you can use in both in TypeScript and JavaScript

Usage examples in TypeScript

Using parametrized event:
var event = new EventT<number>();

event.on((_num: number) => console.log('The number ' + _num + ' was raised'));

event.raise(15);
Using conditional event
var conditionalEvent = new ConditionalEventT<number>();

conditionalEvent.on(
  (_num) => console.log('The number ' + _num + ' is positive'),
  (_num) => _num > 0
  );

conditionalEvent.raise(-1); // Will not be logged
conditionalEvent.raise(12); // Will be logged
Using global event
const globalEvent1 = new GlobalEvent();

globalEvent1.on('some event name', (_num: number) => console.log('The number ' + _num + ' was raised'));

// In some other place
const globalEvent2 = new GlobalEvent();
globalEvent2.raise('some event name', 123); // Will log: "The number 123 was raised"
Raising safely in case one of the registrations throws an error
var event = new Event();

event.on(() => throw 'some error');
event.on(() => console.log('I still want to log'));

event.raiseSafe();
Using ObservableCollection
var collection = new ObservableCollection<number>();

var items:number[] = collection.items;

collection.itemsChanged.on(
  (_args: IItemsChangedEventArgs<number>) => {
    console.log('Added items: ' + _args.added);
    console.log('Removed items: ' + _args.removed);
  });

collection.add(2);
collection.addRange([1,2,3,4,5,6,7,8,9]);

collection.removeMatching(2);
collection.removeMatchingRange([5,6]);
collection.removeAtIndex(0);
collection.removeAtIndices([0,1]);

var size: number = collection.size;

var has7: boolean = collection.contains(7);

collection.clear();
Using ObservableDictionary
var dictionary = new ObservableDictionary<Obejct, Object>();

dictionary.itemsChanged.on(
  _args => {
    console.log('Added key value pairs: ' + _args.added);
    console.log('Removed key value pairs: ' + _args.removed);
  });

var key = { someProp: 1 };
var value = {};
dictionary.add(key, value);

// Be aware: containsKey will work only on keys instances that are inside the dictionary
var containsKey: boolean = dictionary.containsKey(key);
var containsValue: boolean = dictionary.containsValue(value);

// Be aware: getValueByKey will work only on keys instances that are inside the dictionary
var valueByKey: Object = dictionary.getValueByKey(key);

var size: number = dictionary.size;

var keys: Object[] = dictionary.keys;
var values: Object[] = dictionary.values;
var keysAndValues: IKeyValue<Object, Object>[] = dictionary.keysAndValues;

// Be aware: removing will work only on keys instances that are inside the dictionary
dictionary.remove(key);

// If you don't have the instance you can search it:
var foundKey = dictionary.findKey(_ => _.someProp === 1);
dictionary.containsKey(foundKey);
dictionary.getValueByKey(foundKey);
dictionary.remove(foundKey);

dictionary.clear();

Whats next?

Have fun and feel free to use, comment, request, and contribute. I'll keep adding stuff from time to time

turbine-jobscheduler's People

Contributors

ctoesca avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.