Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit a80ad8c

Browse files
committed
Complete implementation (v.1.0.0)
1 parent a57f817 commit a80ad8c

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

Diff for: Gruntfile.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
module.exports = function(grunt) {
4+
grunt.initConfig({
5+
pkg: grunt.file.readJSON('package.json'),
6+
7+
uglify: {
8+
build: {
9+
src: '<%= pkg.name %>.js',
10+
dest: '<%= pkg.name %>.min.js'
11+
}
12+
}
13+
});
14+
15+
grunt.loadNpmTasks('grunt-contrib-uglify');
16+
17+
grunt.registerTask('default', [
18+
'uglify'
19+
]);
20+
};

Diff for: angular-fqueue.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('fqueue', [])
5+
.factory('FixedQueue', function () {
6+
7+
function FixedQueue(size, initialValues ) {
8+
initialValues = (initialValues || []);
9+
10+
// Create the fixed queue array value.
11+
var queue = Array.apply(null, initialValues);
12+
13+
// Store the fixed size in the queue.
14+
queue.fixedSize = size;
15+
16+
// Add the class methods to the queue. Some of these have
17+
// to override the native Array methods in order to make
18+
// sure the queue length is maintained.
19+
queue.push = FixedQueue.push;
20+
queue.splice = FixedQueue.splice;
21+
queue.unshift = FixedQueue.unshift;
22+
23+
// Trim any initial excess from the queue.
24+
FixedQueue.trimTail.call(queue);
25+
26+
// Return the new queue.
27+
return queue;
28+
}
29+
30+
// Trims the queue down to the appropriate size, removing
31+
// items from the beginning of the internal array.
32+
FixedQueue.trimHead = function() {
33+
if (this.length <= this.fixedSize) {
34+
return;
35+
}
36+
Array.prototype.splice.call(this, 0, (this.length - this.fixedSize));
37+
};
38+
39+
// Trims the queue down to the appropriate size, removing
40+
// items from the end of the internal array.
41+
FixedQueue.trimTail = function() {
42+
if (this.length <= this.fixedSize){
43+
return;
44+
}
45+
Array.prototype.splice.call(this, this.fixedSize, (this.length - this.fixedSize));
46+
};
47+
48+
// Calls the native Array methods followed by a trimming method.
49+
FixedQueue.wrapMethod = function(methodName, trimMethod) {
50+
// Create a wrapper that calls the given method.
51+
var wrapper = function() {
52+
// Get the native Array method.
53+
var method = Array.prototype[methodName];
54+
// Call the native method first.
55+
var result = method.apply(this, arguments);
56+
// Trim the queue now that it's been augmented.
57+
trimMethod.call(this);
58+
// Return the original value.
59+
return result;
60+
};
61+
// Return the wrapper method.
62+
return wrapper;
63+
};
64+
65+
FixedQueue.push = FixedQueue.wrapMethod("push", FixedQueue.trimHead);
66+
FixedQueue.splice = FixedQueue.wrapMethod("splice", FixedQueue.trimTail);
67+
FixedQueue.unshift = FixedQueue.wrapMethod('unshift', FixedQueue.trimTail);
68+
69+
/* return the constructor function */
70+
return FixedQueue;
71+
});
72+
})();

Diff for: angular-fqueue.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: bower.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "angular-fqueue",
3+
"version": "1.0.0",
4+
"author": "magiccrafter",
5+
"description": "Fixed size Array (Fixed Queue) for AngularJS",
6+
"keywords": [
7+
"angular",
8+
"fixed-size",
9+
"queue",
10+
"array"
11+
],
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/magiccrafter/angular-fqueue.git"
15+
},
16+
"main": [
17+
"angular-fqueue.js"
18+
],
19+
"ignore": [
20+
"package.json",
21+
"Gruntfile.js"
22+
],
23+
"dependencies": {
24+
"angular": ">= 1.0.8"
25+
}
26+
}

Diff for: package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "angular-fqueue",
3+
"version": "1.0.0",
4+
"author": "magiccrafter",
5+
"description": "Fixed size Array (Fixed Queue) for AngularJS",
6+
"maintainers": [
7+
{
8+
"name": "Nasko Vasilev",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"keywords": [
13+
"angular",
14+
"fixed-size",
15+
"queue",
16+
"array"
17+
],
18+
"license": "MIT",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/magiccrafter/angular-fqueue.git"
22+
},
23+
"devDependencies": {
24+
"grunt": "^0.4.5",
25+
"grunt-cli": "^0.1.13",
26+
"grunt-contrib-uglify": "^0.7.0"
27+
}
28+
}

0 commit comments

Comments
 (0)