Skip to content

Commit

Permalink
refactor: Eschew var for let wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Mar 11, 2016
1 parent 98d99e9 commit 702976a
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dist/lib/Core.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/Cursor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/Instance.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/Model.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/ModelHelpers.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/ModelSpecificInstance.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/caches/MemoryCache.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class Core {
constructor(uri: string, config?: Configuration);
constructor(uri: string | Configuration, config?: Configuration) {

var args = Array.prototype.slice.call(arguments, 0);
let args = Array.prototype.slice.call(arguments, 0);
uri = config = null;
for (var i = 0; i < args.length; i++) {
for (let i = 0; i < args.length; i++) {
if (typeof args[i] == 'string')
uri = args[i];
else if (typeof args[i] == 'object')
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Core {
*/
get url(): string {
if (this._url) return this._url;
var url: string = 'mongodb://';
let url: string = 'mongodb://';

if (this._config.username) {
url += this._config.username;
Expand All @@ -106,7 +106,7 @@ export class Core {
url += '@';
}

var hosts = [];
let hosts = [];

if (this._config.host) {
if (this._config.port)
Expand Down Expand Up @@ -191,7 +191,7 @@ export class Core {
close(): Bluebird<Core> {
return Bluebird.resolve().then(() => {
if (!this._connection) return this;
var conn: MongoDB.Db = this._connection;
let conn: MongoDB.Db = this._connection;
this._connection = null;
conn.close();
return this;
Expand Down
8 changes: 4 additions & 4 deletions lib/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Cursor<TDocument extends { _id?: any }, TInstance> {
* @return {Promise} A promise which is resolved when all operations have been dispatched
*/
forEach(handler: (instance: TInstance) => void, callback?: General.Callback<void>): Bluebird<void> {
var helpers = this.model.helpers;
let helpers = this.model.helpers;
return new Bluebird<void>((resolve, reject) => {
this.cursor.forEach((item: TDocument) => {
this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }).then(handler);
Expand All @@ -62,9 +62,9 @@ export class Cursor<TDocument extends { _id?: any }, TInstance> {
* @return {Promise<TResult[]>} A promise which is fulfilled with the results of the transformations
*/
map<TResult>(transform: (instance: TInstance) => TResult | Bluebird<TResult>, callback?: General.Callback<TResult[]>): Bluebird<TResult[]> {
var helpers = this.model.helpers;
let helpers = this.model.helpers;
return new Bluebird<TResult[]>((resolve, reject) => {
var promises: Bluebird<TResult>[] = [];
let promises: Bluebird<TResult>[] = [];
this.cursor.forEach((item: TDocument) => {
promises.push(this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); })
.then(<(instance) => TResult>transform));
Expand All @@ -81,7 +81,7 @@ export class Cursor<TDocument extends { _id?: any }, TInstance> {
* @return {Promise<TInstance[]>} A promise which resolves with the instances returned by the query
*/
toArray(callback?: General.Callback<TInstance[]>): Bluebird<TInstance[]> {
var helpers = this.model.helpers;
let helpers = this.model.helpers;
return new Bluebird<TDocument[]>((resolve, reject) => {
this.cursor.toArray((err, results: any[]) => {
if (err) return reject(err);
Expand Down
22 changes: 11 additions & 11 deletions lib/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
*/
save(conditions: Object, changes: Object, callback?: General.Callback<TInstance>): Bluebird<TInstance>;
save(...args: any[]): Bluebird<TInstance> {
var callback: General.Callback<any> = null;
var changes: any = null;
var conditions: any = {};
let callback: General.Callback<any> = null;
let changes: any = null;
let conditions: any = {};

Array.prototype.slice.call(args, 0).reverse().forEach((arg) => {
if (typeof arg == 'function') callback = arg;
Expand All @@ -166,11 +166,11 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
_.merge(conditions, { _id: this._modified._id });

if (!changes) {
var validation = this._model.helpers.validate(this._modified);
let validation = this._model.helpers.validate(this._modified);
if (validation.failed) return Bluebird.reject(validation.error).bind(this).nodeify(callback);

var original = this._model.helpers.cloneDocument(this._original);
var modified = this._model.helpers.cloneDocument(this._modified);
let original = this._model.helpers.cloneDocument(this._original);
let modified = this._model.helpers.cloneDocument(this._modified);

modified = this._model.helpers.transformToDB(modified, { document: true });

Expand Down Expand Up @@ -252,7 +252,7 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
* @returns {Promise<TInstance>}
*/
refresh(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
var conditions = { _id: this._original._id };
let conditions = { _id: this._original._id };

return Bluebird.resolve().then(() => {
return new Bluebird<TDocument>((resolve, reject) => {
Expand Down Expand Up @@ -295,7 +295,7 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
* @returns {Promise<TInstance>}
*/
remove(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
var conditions = { _id: this._original._id };
let conditions = { _id: this._original._id };

return Bluebird.resolve().then(() => {
if (this._isNew) return 0;
Expand Down Expand Up @@ -329,7 +329,7 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
*/
first<T>(collection: { [key: string]: T }, predicate: General.Predicate<T>): T;
first<T>(collection: T[]| { [key: string]: T }, predicate: General.Predicate<T>): T {
var result = null;
let result = null;

_.each(collection,(value: T, key) => {
if (predicate.call(this, value, key)) {
Expand All @@ -356,8 +356,8 @@ export class Instance<TDocument extends { _id?: any }, TInstance> {
*/
select<T>(collection: { [key: string]: T }, predicate: General.Predicate<T>): { [key: string]: T };
select<T>(collection: T[]| { [key: string]: T }, predicate: General.Predicate<T>): any {
var isArray = Array.isArray(collection);
var results: any = isArray ? [] : {};
let isArray = Array.isArray(collection);
let results: any = isArray ? [] : {};

_.each(collection,(value: T, key) => {
if (predicate.call(this, value, key)) {
Expand Down
Loading

0 comments on commit 702976a

Please sign in to comment.