Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint with semistandard #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

18 changes: 0 additions & 18 deletions .eslintrc

This file was deleted.

10 changes: 7 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
machine:
node:
version: 5.5.0
version: stable
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"

dependencies:
pre:
- npm install -g npm
override:
- yarn
cache_directories:
- ~/.cache/yarn
47 changes: 32 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,40 @@
"immutable": "3.7.6"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.2.0",
"eslint": "^1.4.1",
"eslint-config-airbnb": "0.0.8",
"mocha": "^2.3.2",
"sinon": "^1.15.4"
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"semistandard": "^11.0.0",
"sinon": "^2.1.0",
"snazzy": "^7.0.0"
},
"scripts": {
"lint": "eslint .",
"lint": "semistandard | snazzy",
"compile": "babel src --out-dir dist",
"test": "NODE_ENV=test mocha --compilers js:babel-core/register",
"prepublish": "npm run compile"
"test": "npm run lint && mocha --compilers js:babel-core/register",
"prepublish": "npm run test && npm run compile"
Copy link
Collaborator

@jameshopkins jameshopkins Apr 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of npm run test here can be removed, due to c8603d2

},
"semistandard": {
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"ignore": [
"dist",
"lib",
"coverage"
]
},
"babel": {
"presets": [
"es2015",
"stage-0"
]
}
}
103 changes: 49 additions & 54 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
const {Iterator} = Iterable;
const NOT_SET = {}; // Sentinel value

function Base(rootData, keyPath, updater, deref, size) {
function Base (rootData, keyPath, updater, deref, size) {
this.size = size;
this._rootData = rootData;
this._keyPath = keyPath;
Expand All @@ -21,29 +21,34 @@ function Base(rootData, keyPath, updater, deref, size) {
}

Base.prototype = {
deref(notSetValue) {
deref (notSetValue) {
return this._rootData.getIn(this._keyPath, notSetValue);
},

// Need test of noSetValue
valueOf(notSetValue) {
return this.deref.call(this, notSetValue);
valueOf (notSetValue) {
return this.deref(notSetValue);
},

get(key, notSetValue) {
get (key, notSetValue) {
return this.getIn([key], notSetValue);
},

getIn(keyPath, notSetValue) {
getIn (keyPath, notSetValue) {
const constructKeyPath = listToKeyPath(keyPath);
if (constructKeyPath.length === 0) {
return this;
}
const value = this._rootData.getIn(newKeyPath(this._keyPath, constructKeyPath), NOT_SET);
return value === NOT_SET ? notSetValue : wrappedValue(this, constructKeyPath, value);
const value = this._rootData.getIn(
newKeyPath(this._keyPath, constructKeyPath),
NOT_SET
);
return value === NOT_SET
? notSetValue
: wrappedValue(this, constructKeyPath, value);
},

set(key, value) {
set (key, value) {
if (arguments.length === 1) {
return updateCursor(this, () => key, []);
}
Expand All @@ -53,88 +58,82 @@ Base.prototype = {
setIn: Map.prototype.setIn,

// Needs tests
remove(key) {
return updateCursor(this, m => m.remove(key), [key]);
remove (key) {
return updateCursor(this, m => m.remove(key), [key]);
},

// Needs tests
delete(key) {
return this.remove.call(this, key);
delete (key) {
return this.remove(key);
},

deleteIn: Map.prototype.deleteIn,

removeIn: Map.prototype.deleteIn,

clear() {
clear () {
return updateCursor(this, m => m.clear());
},

update(keyOrFn, notSetValue, updater) {
return do {
if (arguments.length === 1) {
updateCursor(this, keyOrFn);
} else {
this.updateIn([keyOrFn], notSetValue, updater);
}
};
update (keyOrFn, notSetValue, updater) {
if (arguments.length === 1) {
return updateCursor(this, keyOrFn);
}
return this.updateIn([keyOrFn], notSetValue, updater);
},

updateIn(keyPath, notSetValue, updater) {
updateIn (keyPath, notSetValue, updater) {
return updateCursor(this, m =>
m.updateIn(keyPath, notSetValue, updater)
, keyPath);
},

merge() {
merge () {
return updateCursor(this, m => m.merge.apply(m, arguments));
},

mergeWith() {
mergeWith () {
return updateCursor(this, m => m.mergeWith.apply(m, arguments));
},

mergeIn: Map.prototype.mergeIn,

mergeDeep() {
mergeDeep () {
return updateCursor(this, m => m.mergeDeep.apply(m, arguments));
},

mergeDeepWith() {
mergeDeepWith () {
return updateCursor(this, m => m.mergeDeepWith.apply(m, arguments));
},

mergeDeepIn: Map.prototype.mergeDeepIn,

withMutations(fn) {
withMutations (fn) {
return updateCursor(this, m => (m || Map()).withMutations(fn));
},

cursor(path) {
cursor (path) {
const subKeyPath = valToKeyPath(path);
return subKeyPath.length === 0 ? this : subCursor(this, subKeyPath);
},

__iterate(fn, reverse) {
__iterate (fn, reverse) {
const cursor = this;
const deref = cursor.deref();
return do {
if (deref && deref.__iterate) {
deref.__iterate((v, k) =>
fn(wrappedValue(cursor, [k], v), k, cursor),
reverse
);
} else {
0;
}
};
if (deref && deref.__iterate) {
return deref.__iterate((v, k) =>
fn(wrappedValue(cursor, [k], v), k, cursor),
reverse
);
}
return 0;
},

__iterator(type, reverse) {
__iterator (type, reverse) {
const deref = this.deref();
const cursor = this;
const iterator = deref && deref.__iterator &&
deref.__iterator(Iterator.ENTRIES, reverse);
deref.__iterator(Iterator.ENTRIES, reverse);
return new Iterator(() => {
if (!iterator) {
return { value: undefined, done: true };
Expand All @@ -146,19 +145,15 @@ deref.__iterator(Iterator.ENTRIES, reverse);
const entry = step.value;
const k = entry[0];
const v = wrappedValue(cursor, [k], entry[1]);
return {
value: do {
if (type === Iterator.KEYS) {
k;
} else {
if (type === Iterator.VALUES) {
v;
} else {
[k, v];
}
}
const value = (() => {
if (type === Iterator.KEYS) {
return k;
} if (type === Iterator.VALUES) {
return v;
}
};
return [k, v];
})();
return { value };
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import {valToKeyPath, makeCursor} from './utils';
import createAtom from 'atom-store';

function cursorFrom(data, keyPath, onChange) {
function cursorFrom (data, keyPath, onChange) {
const atom = createAtom(data);
if (arguments.length === 1) {
keyPath = [];
Expand Down
12 changes: 6 additions & 6 deletions src/indexed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import {Seq} from 'immutable';
import Base from './base';
import {updateCursor} from './utils';

function Indexed(rootData, keyPath, updater, deref, size) {
function Indexed (rootData, keyPath, updater, deref, size) {
Base.call(this, rootData, keyPath, updater, deref, size);
}

Indexed.prototype = Object.create(Seq.Indexed.prototype);
Object.assign(Indexed.prototype, Base.prototype);

Indexed.prototype.push = function() {
Indexed.prototype.push = function () {
return updateCursor(this, m => m.push.apply(m, arguments));
};

Indexed.prototype.pop = function() {
Indexed.prototype.pop = function () {
return updateCursor(this, m => m.pop());
};

Indexed.prototype.unshift = function() {
Indexed.prototype.unshift = function () {
return updateCursor(this, m => m.unshift.apply(m, arguments));
};

Indexed.prototype.shift = function() {
Indexed.prototype.shift = function () {
return updateCursor(this, m => m.shift());
};

Indexed.prototype.toString = function() {
Indexed.prototype.toString = function () {
return this.__toString('Cursor [', ']');
};

Expand Down
4 changes: 2 additions & 2 deletions src/keyed.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Seq} from 'immutable';
import Base from './base';

function Keyed(rootData, keyPath, updater, deref, size) {
function Keyed (rootData, keyPath, updater, deref, size) {
Base.call(this, rootData, keyPath, updater, deref, size);
}

Keyed.prototype = Object.create(Seq.Keyed.prototype);
Object.assign(Keyed.prototype, Base.prototype);

Keyed.prototype.toString = function() {
Keyed.prototype.toString = function () {
return this.__toString('Cursor {', '}');
};

Expand Down
Loading