Giter Club home page Giter Club logo

enofjs's Introduction

EnoFJS

Build Status Code Climate Coverage Status Inheritance

Javascript supports private and public out of the box. However inheritance is often claimed impossible or done with prototype.

While inheriting with prototype is not necessarily bad, it however implies that all inheritable properties have to be public and all properties should be public in case a function in the prototype needs to access it.

To make this possible, EnoFJS implements a ClassFactory, handling all the trouble of scoping and inheriting.

var Dog = clazz(function Dog(name){
    this.extend = 'Animal';

    this.private = {
        name: null
    };

    this.protected = {
        nickName: {
            getSet: null
        }
    };

    this.public = {
        barkName: function barkName(){
            return 'Woof, my name is ' + this.private.name +
                ', but you can call me ' +
                this.protected.nickName + '!';
        }
    };

});
var dog = new Dog('fluffy duffy');
dog.setNickName('fluffy');
expect(dog.barkName()).
    toEqual('Woof, my name is fluffy duffy' +
            ', but you can call me fluffy!');

LinkedHashMap

A LinkedHashMap has the advantage of a LinkedList, able to quickly add or remove a Node between already existing nodes. However a LinkedList is slower in finding an entry in the middle of the list, because it has to search through the entire list!

With the implementation of a LinkedHashMap, it keeps the ability to insert or remove nodes like a LinkedList. For searching the implementation of a HashMap is used. This way you have best of both worlds!

var list = new LinkedHashMap();
list.add(0, 'one');
list.add(1, 'two');
list.add(2, 'three');
expect(list.getById(1).getValue()).toEqual('two');
list.addAfter(1, 'an non integer key', 'four');
expect(list.getById('an non integer key').getNext().
                    getValue()).toEqual('three');

Serializable

When sending information over the line in json format, the Serializable clazz can help. This Class will help you in serializing your classes into a json format.

The class also helps you deserialize a serialized object in json format.

var SerializableObject = clazz(function SerializableObject(){
    this.extend = 'Serializable';

    this.constructor = function constructor(serialized){
        this.super(serialized);
    };
});

WhereIt

The whereIt is an extention for the Jasmine test framework. Often you have a test cases where the same process will be executed with different parameters, expecting different results. The whereIt assists in doing this with a simple configuration!

Configuration will be matched to the variable names!

whereIt('should add', function addNumbers(x, y, result){
    expect(calulator.add(x, y)).toEqual(result);
}, [
    {
        x: 1,
        y: 2,
        result: 3
    },
    {
        y: 200,
        x: 2,
        result: 202
    }
]);

ArrayConverters

In modern browsers TypedArrays are introduced. The literal array [] or new Array() do not support the ArrayBuffer out of the box. To convert an literal array into an Uint32Array this extention on the Array.prototype is brought to live.

Usage:

var array = [1,2,3,4];
var uInt32Array = array.toUint32Array();
console.log(uInt32Array[0]); // 67305985
uInt32Array[0] = uInt32Array[0] + 1;
array.readUint32ArrayIn(uInt32Array);
console.log(array); // [2, 2, 3, 4]

enofjs's People

Contributors

enof avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dominikkukacka

enofjs's Issues

Getting the last entry

AS a developer
WHAT retrieve the last entry
WHY to easily retrieve the last entry of an LinkedHashList

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Getting the last entry

THEN
returns the last entry of the list
the last entry should return null when getting next

nodes should have a reference to each other

AS a developer
WHAT node should have a reference to nodes next to it
WHY to easily get the node next to it

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Get the second node by id

THEN
the second node should have a reference to previous and next

Delete middle

AS a developer
WHAT delete an entry in the middle of the list
WHY to easily remove an node in between a list

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Removing the second entry

THEN
The first entry should have the last entry on the next node
The last entry should have the first entry on the previous node

Delete Last

AS a developer
WHAT delete the last entry
WHY to easily delete the last entry of an LinkedHashList

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Deleting the last entry

THEN
The last entry should be the second entry of the initial list
The last entry should return null when getting the next node

ie8 issue with super keyword

ie8 has super keyword reserved and breaks, to make it compatible and also prevent issues with possible future updates from other browsers implementing super, the super keyword will be renamed to sup.

Add before

AS a developer
WHAT add before a node
WHY to easily add an new entry before a node reference

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Adding before the second node

THEN
The added node should be between the first and second node

auto generated is and isSet

this.private = {
  foo: {
    is: false
  },
  bar: {
    isSet: true
  }
} 

will generate

this.public = {
  isFoo: function generatedIs(){
    return this.private.foo;
  },
  isBar: function generatedIs(){
    return this.private.bar;
  },
  setBar: function generatedSet(value){
    this.private.bar = value;
  }
}

Getting the first entry

AS a developer
WHAT retrieve the first entry
WHY to easily retrieve the first entry of an LinkedHashList

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Getting the first entry

THEN
returns the first entry of the list
the first entry should return null when getting previous

Add entry to the first of the list

AS a developer
WHAT add an entry to the list at the first position
WHY to easily add an new entry at the first position without handling reordering

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Adding an entry to the first of the list

THEN
The first entry should be the newly added node
The first entry should have the previously first node as next
The first entry should have null as previous

Add after

AS a developer
WHAT add after a node
WHY to easily add an new entry after a node reference

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Adding after the second node

THEN
The added node should be between the second and last node

Delete First

AS a developer
WHAT delete the first entry
WHY to easily delete the first entry of an LinkedHashList

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Deleting the first entry

THEN
The first entry should be the 2nd entry in the list
The first entry should return null

super is not passed down for an already extended class

GIVEN
Cat extends Animal
Cat.constructor calls Animal.constructor
Kitten extends Cat
Kitten.constructor calls Cat.constructor

WHEN
Kitten is initialized

THEN
Kitten should have called the constructor of Cat and Animal

Add an entry

AS a developer
WHAT add an entry
WHY to easily add an entry to an LinkedHashList

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Adding a new entry

THEN
The new entry should be the last entry
The last entry should have null as next
The previous last entry shoul have the new entry as next

whereIt

AS a developer
WHAT write a test with configurable variables and expectations
WHY to reuse a test easily

Override protected

GIVEN
Cat -> lick throws new Error
Cat -> affect calls lick
Kitten -> lick returns 'LICK'
WHEN
Kitten calls affect
THEN
Kitten -> affect returns LICK

get by id(hash)

AS a developer
WHAT get a node by id(hash)
WHY to easily get a node by position

GIVEN
A LinkedHashList is initialized
The List has 3 entries

WHEN
Get the second node by id

THEN
The second node should be returned

Introduce LinkedHashMap

AS a developer
WHAT use a LinkedHashMap
WHY so I can remove entries and add entries easily

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.