Skip to content

ESLint 💔, Prettier 💅 #14

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

Open
wants to merge 1 commit 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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
"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",
"prettier": "^0.22.0",
"sinon": "^1.15.4"
},
"scripts": {
"lint": "eslint .",
"prettier": "prettier --write --single-quote src/**/*.js",
"compile": "babel src --out-dir dist",
"test": "NODE_ENV=test mocha --compilers js:babel-core/register",
"prepublish": "npm run compile"
Expand Down
32 changes: 20 additions & 12 deletions src/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Iterable, Map} from 'immutable';
import { Iterable, Map } from 'immutable';

import {
listToKeyPath,
Expand All @@ -9,7 +9,7 @@ import {
wrappedValue
} from './utils';

const {Iterator} = Iterable;
const { Iterator } = Iterable;
const NOT_SET = {}; // Sentinel value

function Base(rootData, keyPath, updater, deref, size) {
Expand Down Expand Up @@ -39,8 +39,13 @@ Base.prototype = {
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) {
Expand All @@ -54,7 +59,7 @@ Base.prototype = {

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

// Needs tests
Expand All @@ -81,9 +86,11 @@ Base.prototype = {
},

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

merge() {
Expand Down Expand Up @@ -120,8 +127,8 @@ Base.prototype = {
const deref = cursor.deref();
return do {
if (deref && deref.__iterate) {
deref.__iterate((v, k) =>
fn(wrappedValue(cursor, [k], v), k, cursor),
deref.__iterate(
(v, k) => fn(wrappedValue(cursor, [k], v), k, cursor),
reverse
);
} else {
Expand All @@ -133,8 +140,9 @@ Base.prototype = {
__iterator(type, reverse) {
const deref = this.deref();
const cursor = this;
const iterator = deref && deref.__iterator &&
deref.__iterator(Iterator.ENTRIES, reverse);
const iterator = deref &&
deref.__iterator &&
deref.__iterator(Iterator.ENTRIES, reverse);
return new Iterator(() => {
if (!iterator) {
return { value: undefined, done: true };
Expand Down
2 changes: 1 addition & 1 deletion src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

import {valToKeyPath, makeCursor} from './utils';
import { valToKeyPath, makeCursor } from './utils';
import createAtom from 'atom-store';

function cursorFrom(data, keyPath, onChange) {
Expand Down
4 changes: 2 additions & 2 deletions src/indexed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Seq} from 'immutable';
import { Seq } from 'immutable';
import Base from './base';
import {updateCursor} from './utils';
import { updateCursor } from './utils';

function Indexed(rootData, keyPath, updater, deref, size) {
Base.call(this, rootData, keyPath, updater, deref, size);
Expand Down
2 changes: 1 addition & 1 deletion src/keyed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Seq} from 'immutable';
import { Seq } from 'immutable';
import Base from './base';

function Keyed(rootData, keyPath, updater, deref, size) {
Expand Down
19 changes: 13 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Iterable, Record, Map} from 'immutable';
import { Iterable, Record, Map } from 'immutable';
import KeyedCursor from './keyed';
import IndexedCursor from './indexed';

Expand Down Expand Up @@ -62,7 +62,8 @@ export function valToKeyPath(val) {

export function subCursor(cursor, keyPath, value) {
if (arguments.length < 3) {
return makeCursor( // call without value
return makeCursor(
// call without value
cursor._rootData,
newKeyPath(cursor._keyPath, keyPath),
cursor._updater,
Expand All @@ -80,12 +81,18 @@ export function subCursor(cursor, keyPath, value) {

export function updateCursor(cursor, changeFn) {
const deepChange = arguments.length > 2;
const updateFn = oldState => oldState.updateIn(
const updateFn = oldState =>
oldState.updateIn(
cursor._keyPath,
deepChange ? Map() : undefined,
changeFn
);
return makeCursor(
cursor._updater(updateFn),
cursor._keyPath,
deepChange ? Map() : undefined,
changeFn
cursor._updater,
cursor._deref
);
return makeCursor(cursor._updater(updateFn), cursor._keyPath, cursor._updater, cursor._deref);
}

export function wrappedValue(cursor, keyPath, value) {
Expand Down
Loading