Skip to content

Commit 0a78539

Browse files
authored
fix: allow datasets to be inputs to stores to align with RDF/JS DatasetFactory interface (#505)
* fix: allow datasets to be inputs to stores * chore: use addAll * chore: cleanup
1 parent 023fdb9 commit 0a78539

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/N3Store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default class N3Store {
163163
this._graphs = Object.create(null);
164164

165165
// Shift parameters if `quads` is not given
166-
if (!options && quads && !quads[0])
166+
if (!options && quads && !quads[0] && !(typeof quads.match === 'function'))
167167
options = quads, quads = null;
168168
options = options || {};
169169
this._factory = options.factory || N3DataFactory;
@@ -175,7 +175,7 @@ export default class N3Store {
175175

176176
// Add quads if passed
177177
if (quads)
178-
this.addQuads(quads);
178+
this.addAll(quads);
179179
}
180180

181181
// ## Public properties

test/N3Store-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,16 @@ describe('Store', () => {
24632463
});
24642464
});
24652465
});
2466+
2467+
it('should initialize the store correctly with a another store', () => {
2468+
const quads = new Store([
2469+
new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
2470+
new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')),
2471+
]);
2472+
const store = new Store(quads);
2473+
expect(store.size).toEqual(2);
2474+
expect(store.getQuads()).toHaveLength(2);
2475+
});
24662476
});
24672477

24682478
describe('EntityIndex', () => {

0 commit comments

Comments
 (0)