From 7cf81b6db9c5dc27b1f687bc2028c9fdbc24315b Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Thu, 17 Mar 2016 14:02:42 -0700 Subject: [PATCH] JS: Change the position of the type param to newList etc Fixes #1090 --- clients/crunchbase/ui/src/data.js | 2 +- js/src/datastore-test.js | 2 +- js/src/datastore.js | 6 +++--- js/src/list-test.js | 30 +++++++++++++++--------------- js/src/list.js | 2 +- js/src/map-test.js | 12 ++++++------ js/src/map.js | 4 ++-- js/src/set-test.js | 10 +++++----- js/src/set.js | 2 +- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/clients/crunchbase/ui/src/data.js b/clients/crunchbase/ui/src/data.js index 5f53b03827..a174f6d252 100644 --- a/clients/crunchbase/ui/src/data.js +++ b/clients/crunchbase/ui/src/data.js @@ -187,7 +187,7 @@ export default class DataManager { const map = await this._datasetP; const set = await map.get(r); if (set === undefined) { - return newSet(setType, []); + return newSet([], setType); } invariant(set); diff --git a/js/src/datastore-test.js b/js/src/datastore-test.js index dcebf1ef42..a64529ad61 100644 --- a/js/src/datastore-test.js +++ b/js/src/datastore-test.js @@ -149,7 +149,7 @@ suite('DataStore', () => { const commit = await newCommit('foo', []); const commitRef = writeValue(commit, commit.type, ms); - const datasets = await newMap(types.commitMapType, ['foo', commitRef]); + const datasets = await newMap(['foo', commitRef], types.commitMapType); const rootRef = writeValue(datasets, datasets.type, ms); assert.isTrue(await ms.updateRoot(rootRef, new Ref())); ds = new DataStore(ms); // refresh the datasets diff --git a/js/src/datastore.js b/js/src/datastore.js index 34671598f2..b44162cf85 100644 --- a/js/src/datastore.js +++ b/js/src/datastore.js @@ -27,7 +27,7 @@ type DatasTypes = { let emptyCommitMap: Promise>; function getEmptyCommitMap(): Promise> { if (!emptyCommitMap) { - emptyCommitMap = newMap(getDatasTypes().commitMapType, []); + emptyCommitMap = newMap([], getDatasTypes().commitMapType); } return emptyCommitMap; } @@ -157,7 +157,7 @@ export class DataStore { } async function getAncestors(commits: NomsSet, store: ChunkStore): Promise> { - let ancestors = await newSet(getDatasTypes().commitSetType, []); + let ancestors = await newSet([], getDatasTypes().commitSetType); await commits.map(async (commitRef) => { const commit = await readValue(commitRef, store); await commit.get('parents').map(async (ref) => ancestors = await ancestors.insert(ref)); @@ -168,6 +168,6 @@ async function getAncestors(commits: NomsSet, store: ChunkStore): Promise = []): Promise { const types = getDatasTypes(); - return newSet(types.commitSetType, parents).then(parents => + return newSet(parents, types.commitSetType).then(parents => new Struct(types.commitType, types.commitTypeDef, {value,parents})); } diff --git a/js/src/list-test.js b/js/src/list-test.js index c5ee31b0b6..0db566e1ee 100644 --- a/js/src/list-test.js +++ b/js/src/list-test.js @@ -43,7 +43,7 @@ suite('BuildList', () => { test('set of n numbers, length', async () => { const nums = firstNNumbers(testListSize); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const s = await newList(tr, nums); + const s = await newList(nums, tr); assert.strictEqual(s.ref.toString(), listOfNRef); assert.strictEqual(testListSize, s.length); }); @@ -51,7 +51,7 @@ suite('BuildList', () => { test('toJS', async () => { const nums = firstNNumbers(5000); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const s = await newList(tr, nums); + const s = await newList(nums, tr); assert.strictEqual(s.ref.toString(), listOfNRef); assert.strictEqual(testListSize, s.length); @@ -71,7 +71,7 @@ suite('BuildList', () => { test('insert', async () => { const nums = firstNNumbers(testListSize - 10); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - let s = await newList(tr, nums); + let s = await newList(nums, tr); for (let i = testListSize - 10; i < testListSize; i++) { s = await s.insert(i, [i]); @@ -83,7 +83,7 @@ suite('BuildList', () => { test('append', async () => { const nums = firstNNumbers(testListSize - 10); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - let s = await newList(tr, nums); + let s = await newList(nums, tr); for (let i = testListSize - 10; i < testListSize; i++) { s = await s.append([i]); @@ -95,7 +95,7 @@ suite('BuildList', () => { test('remove', async () => { const nums = firstNNumbers(testListSize + 10); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - let s = await newList(tr, nums); + let s = await newList(nums, tr); let count = 10; while (count-- > 0) { @@ -108,7 +108,7 @@ suite('BuildList', () => { test('splice', async () => { const nums = firstNNumbers(testListSize); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - let s = await newList(tr, nums); + let s = await newList(nums, tr); const splice500At = async (idx: number) => { s = await s.splice(idx, [], 500); @@ -128,7 +128,7 @@ suite('BuildList', () => { const nums = firstNNumbers(testListSize); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const s = await newList(tr, nums); + const s = await newList(nums, tr); const r = writeValue(s, tr, ms); const s2 = await readValue(r, ms); const outNums = await s2.toJS(); @@ -349,8 +349,8 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const l1 = await newList(tr, nums1); - const l2 = await newList(tr, nums2); + const l1 = await newList(nums1, tr); + const l2 = await newList(nums2, tr); const listDiff = await l2.diff(l1); assert.deepEqual(directDiff, listDiff); @@ -368,8 +368,8 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const l1 = await newList(tr, nums1); - const l2 = await newList(tr, nums2); + const l1 = await newList(nums1, tr); + const l2 = await newList(nums2, tr); const listDiff = await l2.diff(l1); assert.deepEqual(directDiff, listDiff); @@ -387,8 +387,8 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const l1 = await newList(tr, nums1); - const l2 = await newList(tr, nums2); + const l1 = await newList(nums1, tr); + const l2 = await newList(nums2, tr); const listDiff = await l2.diff(l1); assert.deepEqual(directDiff, listDiff); @@ -400,8 +400,8 @@ suite('Diff List', () => { const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]); const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64)); - const l1 = await newList(tr, nums1); - const l2 = await newList(tr, nums2); + const l1 = await newList(nums1, tr); + const l2 = await newList(nums2, tr); const listDiff = await l2.diff(l1); assert.deepEqual(directDiff, listDiff); diff --git a/js/src/list.js b/js/src/list.js index 62071fb2e3..a78a8f4634 100644 --- a/js/src/list.js +++ b/js/src/list.js @@ -33,7 +33,7 @@ function newListLeafBoundaryChecker(t: Type): BoundaryCheck ); } -export function newList(type: Type, values: Array): +export function newList(values: Array, type: Type): Promise> { return chunkSequence(null, values, 0, newListLeafChunkFn(type), newIndexedMetaSequenceChunkFn(type), diff --git a/js/src/map-test.js b/js/src/map-test.js index 320ea3bd83..967eaad498 100644 --- a/js/src/map-test.js +++ b/js/src/map-test.js @@ -28,7 +28,7 @@ suite('BuildMap', () => { const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64), makePrimitiveType(Kind.Int64)); - const m = await newMap(tr, kvs); + const m = await newMap(kvs, tr); assert.strictEqual(m.ref.toString(), mapOfNRef); // shuffle kvs, and test that the constructor sorts properly @@ -39,7 +39,7 @@ suite('BuildMap', () => { pairs.sort(() => Math.random() > .5 ? 1 : -1); kvs.length = 0; pairs.forEach(kv => kvs.push(kv.k, kv.v)); - const m2 = await newMap(tr, kvs); + const m2 = await newMap(kvs, tr); assert.strictEqual(m2.ref.toString(), mapOfNRef); }); @@ -51,7 +51,7 @@ suite('BuildMap', () => { const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64), makePrimitiveType(Kind.Int64)); - let m = await newMap(tr, kvs); + let m = await newMap(kvs, tr); for (let i = testMapSize - 10; i < testMapSize; i++) { m = await m.set(i, i + 1); } @@ -67,7 +67,7 @@ suite('BuildMap', () => { const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64), makePrimitiveType(Kind.Int64)); - let m = await newMap(tr, kvs); + let m = await newMap(kvs, tr); for (let i = 0; i < testMapSize; i++) { m = await m.set(i, i + 1); } @@ -83,7 +83,7 @@ suite('BuildMap', () => { const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64), makePrimitiveType(Kind.Int64)); - let m = await newMap(tr, kvs); + let m = await newMap(kvs, tr); for (let i = testMapSize; i < testMapSize + 10; i++) { m = await m.remove(i); } @@ -101,7 +101,7 @@ suite('BuildMap', () => { const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64), makePrimitiveType(Kind.Int64)); - const m = await newMap(tr, kvs); + const m = await newMap(kvs, tr); const r = writeValue(m, tr, ms); const m2 = await readValue(r, ms); diff --git a/js/src/map.js b/js/src/map.js index 698906f1a5..d7dea093ab 100644 --- a/js/src/map.js +++ b/js/src/map.js @@ -64,8 +64,8 @@ function buildMapData(t: Type, kvs: Array): Array { return entries; } -export function newMap(type: Type, - kvs: Array): Promise> { +export function newMap(kvs: Array, type: Type): + Promise> { return chunkSequence(null, buildMapData(type, kvs), 0, newMapLeafChunkFn(type), newOrderedMetaSequenceChunkFn(type), newMapLeafBoundaryChecker(type), diff --git a/js/src/set-test.js b/js/src/set-test.js index 2691f19e42..d41b6eaf9d 100644 --- a/js/src/set-test.js +++ b/js/src/set-test.js @@ -33,19 +33,19 @@ suite('BuildSet', () => { test('set of n numbers', async () => { const nums = firstNNumbers(testSetSize); const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64)); - const s = await newSet(tr, nums); + const s = await newSet(nums, tr); assert.strictEqual(s.ref.toString(), setOfNRef); // shuffle kvs, and test that the constructor sorts properly nums.sort(() => Math.random() > .5 ? 1 : -1); - const s2 = await newSet(tr, nums); + const s2 = await newSet(nums, tr); assert.strictEqual(s2.ref.toString(), setOfNRef); }); test('insert', async () => { const nums = firstNNumbers(testSetSize - 10); const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64)); - let s = await newSet(tr, nums); + let s = await newSet(nums, tr); for (let i = testSetSize - 10; i < testSetSize; i++) { s = await s.insert(i); @@ -57,7 +57,7 @@ suite('BuildSet', () => { test('remove', async () => { const nums = firstNNumbers(testSetSize + 10); const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64)); - let s = await newSet(tr, nums); + let s = await newSet(nums, tr); let count = 10; while (count-- > 0) { @@ -72,7 +72,7 @@ suite('BuildSet', () => { const nums = firstNNumbers(testSetSize); const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64)); - const s = await newSet(tr, nums); + const s = await newSet(nums, tr); const r = writeValue(s, tr, ms); const s2 = await readValue(r, ms); const outNums = []; diff --git a/js/src/set.js b/js/src/set.js index 296d57d334..8d02181155 100644 --- a/js/src/set.js +++ b/js/src/set.js @@ -53,7 +53,7 @@ function buildSetData(t: Type, values: Array): Array { return values; } -export function newSet(type: Type, values: Array): +export function newSet(values: Array, type: Type): Promise> { return chunkSequence(null, buildSetData(type, values), 0, newSetLeafChunkFn(type),