-
-
Save silverbucket/9538acd77d0403da3c691fad6149c63a to your computer and use it in GitHub Desktop.
Revisions
-
silverbucket revised this gist
Jun 29, 2016 . No changes.There are no files selected for viewing
-
silverbucket revised this gist
Jun 29, 2016 . 3 changed files with 162 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,9 @@ <template> <h1>Files List</h1> <button click.trigger="addFile()">Add File</button> <ul> <li repeat.for="file of files._store"> <p>${file.uid} - ${file.name}</p> </li> </ul> </template> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,160 @@ export class App { message = 'Hello World!'; constructor() { this.files = new ArrayKeys({ identifier: 'uid' }); } addFile() { var uid = makeid(5); console.log('adding file: ' + uid); var file = { uid: uid, name: 'filename-' + uid }; this.files.addRecord(file); console.log('files: ', this.files._store); } } function makeid(count) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < count; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } function ArrayKeys(p) { if (typeof p !== 'object') { p = {}; } this._identifier = p.identifier || 'id'; this._store = []; this._idx = []; // array of identifier strings for quick lookup this._emitEvents = false; } ArrayKeys.prototype.emitEvent = function (event, data, dontEmit) { if ((this._emitEvents) && (! dontEmit)) { this.events.emit(event, data); } }; ArrayKeys.prototype.getIdentifiers = function () { var ids = []; for (var i = this._store.length - 1; i >= 0; i = i - 1) { ids[ids.length] = this._store[i][this._identifier]; } return ids; }; ArrayKeys.prototype.getRecord = function (id) { for (var i = this._store.length - 1; i >= 0; i = i - 1) { if (this._store[i][this._identifier] === id) { return this._store[i]; } } return undefined; }; ArrayKeys.prototype.exists = function (id) { if (this.getIndex(id) >= 0) { return true; } else { return false; } }; // faster than using indexOf ArrayKeys.prototype.getIndex = function (id) { for (var i = this._idx.length - 1; i >= 0; i = i - 1) { if (this._idx[i] === id) { return i; } } return -1; }; ArrayKeys.prototype.addRecord = function (record) { if (typeof record !== 'object') { throw new Error('cannot add non-object records.'); } else if (!record[this._identifier]) { throw new Error('cannot add a record with no `' + this._identifier + '` property specified.'); } var removed = this.removeRecord(record[this._identifier], true); this._idx[this._idx.length] = record[this._identifier]; this._store[this._store.length] = record; setTimeout(function () { if (removed) { setTimeout(this.emitEvent.bind(this, 'update', record), 0); } else { setTimeout(this.emitEvent.bind(this, 'add', record), 0); } }.bind(this), 0); return true; }; ArrayKeys.prototype.removeRecord = function (id, dontEmit) { var idx = this.getIndex(id); if (idx < 0) { return false; } // start looking for the record at the same point as the idx entry for (var i = idx; i >= 0; i = i - 1) { if ((this._store[i]) && (this._store[i][this._identifier] === id)) { this._store.splice(i, 1); this._idx.splice(idx, 1); setTimeout(this.emitEvent.bind(this, 'remove', id, dontEmit), 0); return true; } } // if it was not found, start at the end and break at the idx number for (var n = this._store.length - 1; n >= idx; n = n - 1) { if ((this._store[i]) && (this._store[n][this._identifier] === id)) { this._store.splice(n, 1); this._idx.splice(idx, 1); setTimeout(this.emitEvent.bind(this, 'remove', id, dontEmit), 0); return true; } } return false; }; ArrayKeys.prototype.forEachRecord = function (cb) { var count = 0; var self = this; var finished = function () {}; setTimeout(function () { for (var i = self._store.length - 1; i >= 0; i = i - 1) { count += 1; setTimeout(cb(self._store[i]), 0); } setTimeout(finished(count), 0); }, 0); return { finally: function (func) { finished = func; } }; }; ArrayKeys.prototype.getCount = function () { return this._store.length; }; ArrayKeys.prototype.removeAll = function () { for (var i = this._store.length - 1; i >= 0; i = i - 1) { delete this._store[i]; } this._store = []; }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ <body aurelia-app> <h1>Loading...</h1> <script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> -
silverbucket revised this gist
Jun 29, 2016 . 2 changed files with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ export class App { message = 'Hello World!'; test = new Test(); files = new ArrayKeys(); } function Test() {} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ <body aurelia-app> <h1>Loading...</h1> <script src="https://raw.githubusercontent.com/silverbucket/array-keys/master/browser/array-keys.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> -
jdanyow revised this gist
Apr 12, 2016 . No changes.There are no files selected for viewing
-
jdanyow revised this gist
Apr 11, 2016 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,12 @@ <body aurelia-app> <h1>Loading...</h1> <script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> <script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> <script> require(['aurelia-bootstrapper']); </script> </body> </html> -
jdanyow revised this gist
Mar 6, 2016 . 3 changed files with 3 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,14 +2,13 @@ <html> <head> <title>Aurelia</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body aurelia-app> <h1>Loading...</h1> <script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> <script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> <script> System.import('aurelia-bootstrapper'); </script> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
jdanyow created this gist
Feb 22, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ <template> <h1>${message}</h1> </template> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ export class App { message = 'Hello World!'; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <!doctype html> <html> <head> <title>Aurelia</title> <link rel="stylesheet" href="styles.css"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body aurelia-app="main"> <h1>Loading...</h1> <script src="https://cdn.rawgit.com/jdanyow/aurelia-plunker/v0.11.10/jspm_packages/system.js"></script> <script src="https://cdn.rawgit.com/jdanyow/aurelia-plunker/v0.11.10/config2.js"></script> <script> System.import('aurelia-bootstrapper'); </script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ /******************************************************************************* * The following two lines enable async/await without using babel's * "runtime" transformer. Uncomment the lines if you intend to use async/await. * * More info here: https://github.com/jdanyow/aurelia-plunker/issues/2 */ //import regeneratorRuntime from 'babel-runtime/regenerator'; //window.regeneratorRuntime = regeneratorRuntime; /******************************************************************************/ export function configure(aurelia) { aurelia.use .standardConfiguration() .developmentLogging(); aurelia.start().then(a => a.setRoot()); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ /* Styles go here */