Skip to content

Commit

Permalink
First pass of introducing protocols for associative and indexed values
Browse files Browse the repository at this point in the history
  • Loading branch information
brianneisler committed Apr 19, 2017
1 parent 4c34ed0 commit 58e2347
Show file tree
Hide file tree
Showing 106 changed files with 906 additions and 360 deletions.
93 changes: 86 additions & 7 deletions docs/API.md
Expand Up @@ -167,7 +167,7 @@
+ [`isArguments()`](#isarguments) **Lo*
+ [`isArray()`](#isarray)
+ [`isArrayBuffer()`](#isarraybuffer) **Lo*
+ [`isArrayLike()`](#isarraylike) **Lo*
+ [`isArrayLike()`](#isarraylike)
+ [`isArrayLikeObject()`](#isarraylikeobject) **Lo*
+ [`isAssociative()`](#isassociative)
+ [`isBatchable()`](#isbatchable)
Expand Down Expand Up @@ -215,14 +215,14 @@
+ [`isKey()`](#iskey)
+ [`isKeyable()`](#iskeyable)
+ [`isKeyed()`](#iskeyed)
+ [`isLength()`](#islength) **Lo*
+ [`isLength()`](#islength)
+ [`isMap()`](#ismap) **Lo*
+ [`isMatch()`](#ismatch)
+ [`isMatchWith()`](#ismatchwith) **TODO*
+ [`isMutable()`](#ismutable)
+ [`isNaN()`](#isnan) **Lo*
+ [`isNative()`](#isnative) **Lo*
+ [`isNil()`](#isnil) **Lo*
+ [`isNil()`](#isnil)
+ [`isNull()`](#isnull) **Lo*
+ [`isNumber()`](#isnumber)
+ [`isObject()`](#isobject)
Expand All @@ -234,7 +234,7 @@
+ [`isSet()`](#isset) **Lo*
+ [`isShallowEqual()`](#isshallowequal)
+ [`isString()`](#isstring)
+ [`isSymbol()`](#issymbol) **Lo*
+ [`isSymbol()`](#issymbol)
+ [`isTypedArray()`](#istypedarray) **Lo*
+ [`isUndefined()`](#isundefined) **Lo*
+ [`isWeakMap()`](#isweakmap) **Lo*
Expand All @@ -245,7 +245,7 @@
+ [`lt()`](#lt) **Lo*
+ [`lte()`](#lte) **Lo*
+ [`toArray()`](#toarray)
+ [`toFinite()`](#tofinite) **Lo*
+ [`toFinite()`](#tofinite)
+ [`toIm()`](#toim)
+ [`toImIndexedSeq()`](#toimindexedseq)
+ [`toImIterable()`](#toimiterable)
Expand All @@ -271,11 +271,11 @@
+ [`toImSetSeq()`](#toimsetseq)
+ [`toImStack()`](#toimstack)
+ [`toIndexed()`](#toindexed)
+ [`toInteger()`](#tointeger) **Lo*
+ [`toInteger()`](#tointeger)
+ [`toIterable()`](#toiterable)
+ [`toLength()`](#tolength) **Lo*
+ [`toMutable()`](#tomutable)
+ [`toNumber()`](#tonumber) **Lo*
+ [`toNumber()`](#tonumber)
+ [`toObject()`](#toobject)
+ [`toPlainObject()`](#toplainobject) **Lo*
+ [`toSageInteger()`](#tosafeinteger) **Lo*
Expand Down Expand Up @@ -674,6 +674,19 @@ isArray(
Returns `true` if value is an `Array`. Otherwise `false`.


### `isArrayLike()`

```js
isArrayLike(
data: any
): boolean
```

Returns `true` if value is array-like. Otherwise `false`.

A value is considered array-like if it's not a function and has a `value.length` that's an integer greater than or equal to 0 and less than or equal to `Number.MAX_SAFE_INTEGER`.


### `isBoolean()`

```js
Expand Down Expand Up @@ -852,6 +865,28 @@ isImmutableStack(
Returns `true` if data is of type [`Immutable.Stack`][Immutable.Stack]. Otherwise `false`.


### `isLength()`

```js
isLength(
data: any
): boolean
```

Returns `true` if value is a valid array-like length. Otherwise `false`.


### `isNil()`

```js
isNil(
data: any
): boolean
```

Returns `true` if value is `null` or `undefined`. Otherwise `false`.


### `isNumber()`

```js
Expand Down Expand Up @@ -885,6 +920,50 @@ isString(
Returns `true` if value is classified as a `String` primitive or object. Otherwise `false`.


### `isSymbol()`

```js
isSymbol(
data: any
): boolean
```

Returns `true` if value is classified as a `Symbol` primitive or object. Otherwise `false`.


### `toFinite()`

```js
toFinite(
data: any
): number
```

Converts value to a finite number.


### `toInteger()`

```js
toInteger(
data: any
): number
```

Converts value to an integer.


### `toNumber()`

```js
toNumber(
data: any
): number
```

Converts value to a number.


## Object and Immutable.Map

### `set()`
Expand Down
14 changes: 7 additions & 7 deletions docs/README.md
Expand Up @@ -161,7 +161,7 @@
+ [`isArguments()`](./API.md#isarguments) **Lo*
+ [`isArray()`](./API.md#isarray)
+ [`isArrayBuffer()`](./API.md#isarraybuffer) **Lo*
+ [`isArrayLike()`](./API.md#isarraylike) **Lo*
+ [`isArrayLike()`](./API.md#isarraylike)
+ [`isArrayLikeObject()`](./API.md#isarraylikeobject) **Lo*
+ [`isAssociative()`](./API.md#isassociative)
+ [`isBatchable()`](./API.md#isbatchable)
Expand Down Expand Up @@ -209,14 +209,14 @@
+ [`isKey()`](./API.md#iskey)
+ [`isKeyable()`](./API.md#iskeyable)
+ [`isKeyed()`](./API.md#iskeyed)
+ [`isLength()`](./API.md#islength) **Lo*
+ [`isLength()`](./API.md#islength)
+ [`isMap()`](./API.md#ismap) **Lo*
+ [`isMatch()`](./API.md#ismatch)
+ [`isMatchWith()`](./API.md#ismatchwith) **TODO*
+ [`isMutable()`](./API.md#ismutable)
+ [`isNaN()`](./API.md#isnan) **Lo*
+ [`isNative()`](./API.md#isnative) **Lo*
+ [`isNil()`](./API.md#isnil) **Lo*
+ [`isNil()`](./API.md#isnil)
+ [`isNull()`](./API.md#isnull) **Lo*
+ [`isNumber()`](./API.md#isnumber)
+ [`isObject()`](./API.md#isobject)
Expand All @@ -228,7 +228,7 @@
+ [`isSet()`](./API.md#isset) **Lo*
+ [`isShallowEqual()`](./API.md#isshallowequal)
+ [`isString()`](./API.md#isstring)
+ [`isSymbol()`](./API.md#issymbol) **Lo*
+ [`isSymbol()`](./API.md#issymbol)
+ [`isTypedArray()`](./API.md#istypedarray) **Lo*
+ [`isUndefined()`](./API.md#isundefined) **Lo*
+ [`isWeakMap()`](./API.md#isweakmap) **Lo*
Expand All @@ -239,7 +239,7 @@
+ [`lt()`](./API.md#lt) **Lo*
+ [`lte()`](./API.md#lte) **Lo*
+ [`toArray()`](./API.md#toarray)
+ [`toFinite()`](./API.md#tofinite) **Lo*
+ [`toFinite()`](./API.md#tofinite)
+ [`toIm()`](./API.md#toim)
+ [`toImIndexedSeq()`](./API.md#toimindexedseq)
+ [`toImIterable()`](./API.md#toimiterable)
Expand All @@ -265,11 +265,11 @@
+ [`toImSetSeq()`](./API.md#toimsetseq)
+ [`toImStack()`](./API.md#toimstack)
+ [`toIndexed()`](./API.md#toindexed)
+ [`toInteger()`](./API.md#tointeger) **Lo*
+ [`toInteger()`](./API.md#tointeger)
+ [`toIterable()`](./API.md#toiterable)
+ [`toLength()`](./API.md#tolength) **Lo*
+ [`toMutable()`](./API.md#tomutable)
+ [`toNumber()`](./API.md#tonumber) **Lo*
+ [`toNumber()`](./API.md#tonumber)
+ [`toObject()`](./API.md#toobject)
+ [`toPlainObject()`](./API.md#toplainobject) **Lo*
+ [`toSageInteger()`](./API.md#tosafeinteger) **Lo*
Expand Down
85 changes: 85 additions & 0 deletions src/core/__tests__/delete.test.js
@@ -0,0 +1,85 @@
import 'babel-polyfill'
import { delete as _delete } from '../'
import { withHintSameType, withMultipleTypeInputs } from './recompose'
import { immutableTest } from './tests'
import { indexed, keyed } from './types'
import { compose, runTests, setupTest } from './util'

const enhance = compose(
withMultipleTypeInputs,
withHintSameType
)

const testDelete = enhance(immutableTest(({ data, path }) => _delete(data, path)))

describe('delete', function() {
const context = setupTest()
const { Symbol } = context

const symbolA = Symbol('a')

const tests = {
'should delete indexed `data` on `path`': {
inputs: {
data: {
value: ['a', 'b', 'c'],
types: indexed()
},
path: {
value: 1
}
},
expected: ['a', 'c']
},
'should delete keyed `data` on `path`': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c':3 },
types: keyed()
},
path: {
value: 'c'
}
},
expected: { 'a':1, 'b':2 }
},
'should delete deep `data` on `path` with nested object': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c': { 'd': 3, 'e': 4 } },
types: keyed()
},
path: {
value: 'c.d'
}
},
expected: { 'a':1, 'b':2, 'c': { 'e': 4 } }
},
'should delete deep `data` on `path` with nested array': {
inputs: {
data: {
value: { 'a':1, 'b':2, 'c': [3, 4, 5] },
types: keyed()
},
path: {
value: 'c.1'
}
},
expected: { 'a':1, 'b':2, 'c': [3, 5] }
},
'should delete keyed `data` with symbol `path`': {
inputs: {
data: {
value: { [symbolA]:1, 'b':2, 'c':3 }
//types: keyed() //TODO BRN: immutable types do not seem to be working with symbols
},
path: {
value: symbolA
}
},
expected: { 'b':2, 'c':3 }
}
}

runTests(tests, context, testDelete)
})
90 changes: 62 additions & 28 deletions src/core/__tests__/push.test.js
@@ -1,35 +1,69 @@
import 'babel-polyfill'
import { expect } from 'chai'
import { push } from '../'
import Immutable from 'immutable'
import { withHintSameType, withMultipleTypeInputs } from './recompose'
import { immutableTest } from './tests'
import { indexed, indexedWithoutStack, stack } from './types'
import { compose, runTests, setupTest } from './util'

describe('push', function() {
const enhance = compose(
withMultipleTypeInputs,
withHintSameType
)

const testPush = enhance(immutableTest(({ data, values }) => push(data, ...values)))

it('pushes to mutable array', function() {
const array = []
const result = push(array, 'test1')
expect(result).not.to.equal(array) //expect new array
expect(array).to.deep.equal([]) //do no modify array
expect(result).to.deep.equal([
'test1'
])
})
describe('push', function() {

it('returns array if data is empty', function() {
const data = null
const result = push(data, 'test1')
expect(result).to.deep.equal([
'test1'
])
})
const context = setupTest()
const tests = {
'pushes `values` to empty indexed `data`': {
inputs: {
data: {
value: [],
types: indexed()
},
values: {
value: ['a']
}
},
expected: ['a']
},
'pushes `value` to null data': {
inputs: {
data: {
value: null
},
values: {
value: ['b']
}
},
expected: ['b']
},
'pushes multiple `values` to indexed `data`': {
inputs: {
data: {
value: ['a'],
types: indexedWithoutStack()
},
values: {
value: [ 'b', 'c' ]
}
},
expected: [ 'a', 'b', 'c' ]
},
'pushes multiple `values` to front of `Stack`': {
inputs: {
data: {
value: ['a'],
types: stack()
},
values: {
value: [ 'b', 'c' ]
}
},
expected: [ 'b', 'c', 'a' ]
}
}

it('pushes to immutable List', function() {
const data = Immutable.fromJS([])
const result = push(data, 'test1')
expect(result).not.to.equal(data) //expect new array
expect(Immutable.List.isList(result)).to.be.true
expect(result.toJS()).to.deep.equal([
'test1'
])
})
runTests(tests, context, testPush)
})

0 comments on commit 58e2347

Please sign in to comment.