Git Product home page Git Product logo

prime's Introduction

prime

Package Info NPM Version Coverage Status Build Status Dependencies Status DevDependencies Status

  1. fundamental, basic, essential.
  2. make (something) ready for use or action.
  3. archetypal, prototypical, typical, classic.

Description

prime is an Object Oriented JavaScript library. It helps you with prototypal inheritance and contains generic utilities for every-day JavaScripting.

No Native JavaScript Objects were harmed in the making of this library.

Modules Overview

A short overview of the available modules. For more information, refer to the documentation.

prime

The function to create new primes.

var prime = require("prime")

var Animal = prime({
    say: function(){
        return "!!"
    }
})

var Emitter = require("prime/emitter")

var Cat = prime({
    inherits: Animal,
    mixin: Emitter,
    say: function(){
        return "meaow" + Cat.parent.say.call(this)
    }
})

prime/emitter

The event emitter.

var Emitter = require("prime/emitter")

var Dog = prime({
    inherits: Animal,
    mixin: Emitter,
    say: function(){
        var word = "wuff" + Dog.parent.say.call(this)
        this.emit("say", word)
        return word
    }
})

var barkley = new Dog

barkley.on("say", function(word){
    console.log("barkley barked", word)
})

prime/map

Map-like implementation.

var Map = require("prime/map")

var map = new Map()

map.set(domElement, "header")
map.set(domElement2, "footer")
map.get(domElement) // "header"
map.get(domElement2) // "footer"

prime/defer

Optimized timeouts / immediates / animationFrames.

var defer = require("prime/defer")

defer.frame(function() {
    console.log('on next animation frame');
});

defer.immediate(function() {
    console.log('on platform next tick.');
});

defer.timeout(function() {
    console.log('late');
}, 500);

When all else fails, read the full documentation.

prime's People

Contributors

arian avatar cpojer avatar danfooo-sp avatar devmanny avatar gcheung55 avatar ibolmo avatar kamicane avatar kentaromiura avatar sergiocrisostomo avatar subtlegradient avatar timwienk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prime's Issues

implement function/throttle

Which limits the execution rate by a specific amount of milliseconds, requestAnimationFrame or the current tick.

for specific timeout

throttle.timeout(fn, ms) || throttle(fn, ms)

for requestAnimationFrame

throttle.frame(fn)

current tick

throttle.immediate(fn) || throttle(fn)

implement function/debounce

Which runs the original function after the debounced function is not being called for a specific amount of milliseconds. Second argument to call the function when the debounced version is invoked.

debounce(fn, true / false)

prime.create inconsistent on new vs older environments.

Because prime.create uses native ES5 Object.create when available it will support prime.create(null), useful for creating blank data objects, in newer environments but not older environments. Also because it uses Object.create in newer environments it will support a second descriptors argument, but not in older environments.

Question to "mixin" other Primes / Objects

Hi,

if a create a Prime that is only used as a mixin for other primes, it seems, that "direct" variables of this prime are instantiated correctly, but variables inside an object in this prime are mixed, as they were static.

Look at these example please, to understand correctly, what i mean:

var prime = require('prime');

var Counter = prime({
    counterVariable: 0,
    counterObject: {
        anotherCounterVariable: 0
    }, 
    raiseCounters: function() {
        this.counterVariable++;
        this.counterObject.anotherCounterVariable++;

        this.logCounters();
    }, 
    logCounters: function() {
        console.log('Counters', this.counterVariable, this.counterObject.anotherCounterVariable);
    }
});

var Foo = prime({
    mixin: Counter
});

var Bar = prime({
    mixin: Counter
});

var foo = new Foo();
var bar = new Bar();

foo.raiseCounters();
bar.raiseCounters();

foo.raiseCounters();
bar.raiseCounters();

the output in console is:

Counters 1 1
Counters 1 2
Counters 2 3
Counters 2 4

SocounterVariable is instantiated and mixed in correctly in the different Primes.
But counterObject.anotherCounterVariable stays static over the different Primes "Foo" and "Bar".

Is this a bug? Or should we tread it like an undocumentet feature? I dont think, that this is a good behaviour of Prime-mixin...

Method modifiers

Is there any plan to support method modifiers, such as in Joose, for example?

Ditch ES5 array methods in favor of simplified fallbacks.

Avoiding ES5 array methods gives you better performance, portability, and the ability to add custom features.

Prime's current implementation relies on the presence of a native method first, which means if the method is shimmed incorrectly (which happens all the time) code built on Prime will be affected. Libs like NWMatcher, Dojo, YUI, Ember, and Lo-Dash detect and avoid shims increasing their portability because they can be used in environments which devs may not entirely control.

Because Prime is native first, its fallbacks must also follow spec or introduce cross-browser inconsistencies. Following spec cripples the perf of its fallbacks too because they have to do the (i in this) checks. Even if Prime follows the ES5 spec it still falls to cross-browser inconsistencies of what various engines consider sparse (IE < 9 will consider var a = ['', undefined, null] sparse, and other engines won't).

Because it's not limited to the ES5 specification of Array#map it can customize how callbacks are handled allowing for syntax like _.map(users 'username') to return an array of each user's username property value. Also notice it avoids .call in the loop by only performing the thisArg binding if it's passed. Finally, it fast paths arrays and falls back to the internal each function for objects, strings, and arguments objects. This allows it to fast path the common case while still providing consistent cross-environment support for the other cases.

unload to others for common low level methods

Prime could use a lib like Lo-Dash for its low level utility methods. Lo-Dash covers issues like old IE's [[DontEnum]] bug that prime.each handles, but also fixes Firefox/WebKit/Opera prototype enumeration bugs when iterating functions, shift and splice bugs on array-like objects, function type checking bugs, and others.

Here is a list of API Prime could punt:

  • prime.each => _.forIn
  • prime.has => _.has
  • array.count => _.size
  • array.every => _.every
  • array.filter => _.filter
  • array.forEach => _.forEach
  • array.indexOf => _.indexOf
  • array.isArray => _.isArray
  • array.lastIndexOf => _.lastIndexOf
  • array.map => _.map
  • array.some => _.some
  • number.random => _.random
  • number.times => _.times
  • object.each => _.forIn
  • object.filter => _.pick
  • object.keys => _.keys
  • object.map => _.assign
  • object.values => _.values
  • type => _.isArguments, _.isArray, _.isBoolean, _.isDate, _.isFunction, _.isRegExp

"Collections" methods, including _.every and _.some, will also work with strings, array-like objects and Object objects.

There's also support for intuitive chaining as well and has something similar to Prime's implement through _.mixin.

Prime would also get support for

  • _.bind, _.clone, _.cloneDeep, _.defaults, _.extend, _.isFinite, _.isNaN, _.isObject, _.isPlainObject, _.merge, _.partial, _.partialRight, _.reduce, _.reduceRight, and lots of other methods.

You can leverage custom builds to include the methods and exports needed.

For the web?

The NPM title of Prime is:

prime, an OOP JavaScript library for node and the web.

How exactly is this library for the web?

Because it's not AMD compliant and also not available to Bower (or something equivalent).

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.