Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-datastore

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-datastore - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

12

lib/dataStore.js
"use strict";
const lodash = require("lodash");
const SectionedList = require("sectioned-list");
const arrays = require("./utils/arrays");

@@ -13,2 +15,6 @@ const numbers = require("./utils/numbers");

this._sectionedList = new SectionedList({
sectionSizes: config.sectionSizes
});
this._beforeAddObjectProcessor;

@@ -57,2 +63,6 @@

get sections() {
return this._sectionedList.sections;
}
hasContents() {

@@ -273,2 +283,4 @@ return this.size > 0;

}
this._sectionedList.addItem(object);
}

@@ -275,0 +287,0 @@

6

package.json
{
"name": "array-datastore",
"version": "1.1.3",
"version": "1.2.0",
"description": "A datastore to store unique objects in an array.",

@@ -26,3 +26,5 @@ "main": "index.js",

},
"dependencies": {},
"dependencies": {
"sectioned-list": "^1.1.0"
},
"devDependencies": {

@@ -29,0 +31,0 @@ "babel-eslint": "^8.2.3",

@@ -40,2 +40,3 @@ A datastore to easily and consistently store unique objects in an array.

- `clearPlaceholders()` Remove the placeholder objects from the store.
- `sections` Get the sections of the datastore. As you add values to the datastore, they are also added to a `sectionedList`. Note that this sectionedList can only be added to and no items will ever be removed from it; this may change in the future. See [sectioned-list](https://github.com/Lwdthe1/sectioned-list) library for details.

@@ -52,2 +53,6 @@ See the tests (`tests/dataStore_test.js`) to see how these methods are used.

### sectionSizes: Array<Number>
See [sectioned-list](https://github.com/Lwdthe1/sectioned-list) library.
## Example

@@ -54,0 +59,0 @@

@@ -253,2 +253,73 @@ "use stict";

describe("#sections()", function() {
it("Should return all sections in the store when custom section sizes not provided.", () => {
const store = ArrayDataStore.instance({});
const obj1 = { id: 123, name: "Lincoln" };
const obj2 = { id: 234, name: "Daniel" };
const obj3 = { id: 345 };
const obj4 = { id: 456 };
const obj5 = { id: 567 };
const obj6 = { id: 678 };
const obj7 = { id: 789 };
const obj8 = { id: 891 };
const obj9 = { id: 911 };
const obj10 = { id: 1011 };
const obj11 = { id: 1112 };
const obj12 = { id: 1213 };
store.addUniqueObjects([
obj1,
obj2,
obj3,
obj1,
obj4,
obj5,
obj6,
obj7,
obj8,
obj9,
obj10,
obj11,
obj12
]);
assert.deepEqual(
store.sections.map(({ items }) => items),
[
[obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10],
[obj11, obj12]
]
);
});
it("Should return all sections in the store when custom section sizes provided.", () => {
const store = ArrayDataStore.instance({ sectionSizes: [1, 2, 0, 3] });
const obj1 = { id: 123, name: "Lincoln" };
const obj2 = { id: 234, name: "Daniel" };
const obj3 = { id: 345 };
const obj4 = { id: 456 };
const obj5 = { id: 567 };
const obj6 = { id: 678 };
const obj7 = { id: 789 };
const obj8 = { id: 891 };
store.addUniqueObjects([
obj1,
obj2,
obj3,
obj1,
obj4,
obj5,
obj6,
obj7,
obj8
]);
assert.deepEqual(
store.sections.map(({ items }) => items),
[[obj1], [obj2, obj3], [], [obj4, obj5, obj6], [obj7, obj8]]
);
});
});
describe("#getObjectById()", function() {

@@ -255,0 +326,0 @@ it("Should succeed to get an object by its id when exists in the store", () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc