Skip to content

Commit 239a3e8

Browse files
authored
Merge pull request #10 from XbyOrange/v1.1.0
V1.1.0
2 parents 1d02d25 + cae3b06 commit 239a3e8

12 files changed

+293
-152
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### BREAKING CHANGES
1313

14+
## [1.1.0] - 2019-06-25
15+
### Added
16+
- Expose `_root` property in queried instances to allow identify the root instance.
17+
- Emit `_root` property on cleanAny events.
18+
19+
### Fixed
20+
- Expose custom queries methods in `customQueries` property, as described in documentation.
21+
- Expose test.queries properties for concurrent sources.
22+
1423
## [1.0.0] - 2019-06-03
1524
### BREAKING CHANGES
1625
- Forked from xByOrange reactive-data-source v1.7.0 private library. (Only Origin and Selector are exposed from now)

LICENSE

+1-12
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,7 @@
175175

176176
END OF TERMS AND CONDITIONS
177177

178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
178+
Copyright 2019 XByOrange
190179

191180
Licensed under the Apache License, Version 2.0 (the "License");
192181
you may not use this file except in compliance with the License.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xbyorange/mercury",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Mercury. Reactive CRUD data layer",
55
"keywords": [
66
"reactive",

sonar-project.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sonar.organization=javierbrea
22
sonar.projectKey=xbyorange-mercury
3-
sonar.projectVersion=1.0.0
3+
sonar.projectVersion=1.1.0
44

55
sonar.sources=src,test
66
sonar.exclusions=node_modules/**

src/Cache.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ export class Cache {
1616
});
1717
}
1818

19-
getAnyData(queryUniqueId) {
19+
getAnyData(queryUniqueId, _root) {
2020
return {
2121
action: "clean",
2222
source: {
2323
_id: `${this._id}${queryUniqueId ? `-${queryUniqueId}` : ""}`,
24-
_queryId: queryUniqueId
24+
_queryId: queryUniqueId,
25+
_root
2526
}
2627
};
2728
}
2829

29-
clean(query) {
30+
clean(query, _root) {
3031
if (query) {
3132
const queryIdentifier = queryId(query);
3233
delete this._cachedData[queryIdentifier];
3334
this._eventEmitter.emit(cleanCacheEventName(query), query);
34-
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(queryIdentifier));
35+
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(queryIdentifier, _root));
3536
} else {
3637
this._reset();
37-
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData());
38+
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(null, _root));
3839
}
3940
}
4041

src/Origin.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Origin {
2424
typeof defaultValue !== "undefined" ? cloneDeep(defaultValue) : defaultValue;
2525

2626
this._customQueries = {};
27+
this.customQueries = {};
2728
this.test = {};
2829

2930
this._createBaseMethods();
@@ -82,10 +83,10 @@ export class Origin {
8283
}
8384

8485
_clean(query) {
85-
this._cache.clean(query);
86+
this._cache.clean(query, this);
8687
}
8788

88-
_createQueryMethods(query, queryId) {
89+
_createQueryMethods(query, id) {
8990
const methods = {};
9091

9192
const updateData = (data, methodName, action, params) => {
@@ -106,7 +107,7 @@ export class Origin {
106107
methods[methodName].error = newData.error;
107108
this._emitChange(query, methodName);
108109
this._emitChangeAny({
109-
source: this._queries[queryId],
110+
source: this._queries[id],
110111
method: methodName,
111112
action,
112113
params
@@ -219,8 +220,10 @@ export class Origin {
219220
newQuery._id = `${this._id}${queryUniqueId ? `-${queryUniqueId}` : ""}`;
220221
newQuery.actions = actions;
221222
newQuery._isSource = true;
223+
newQuery._root = this;
222224

223225
newQuery.query = queryExtension => this.query(merge(query, queryExtension));
226+
newQuery.customQueries = this._customQueries;
224227

225228
Object.keys(this._customQueries).forEach(queryKey => {
226229
newQuery[queryKey] = queryExtension => {
@@ -236,6 +239,7 @@ export class Origin {
236239
addCustomQueries(customQueries) {
237240
Object.keys(customQueries).forEach(queryKey => {
238241
this._customQueries[queryKey] = customQueries[queryKey];
242+
this.customQueries[queryKey] = customQueries[queryKey];
239243
this.test.customQueries = this.test.customQueries || {};
240244
this.test.customQueries[queryKey] = customQueries[queryKey];
241245
this[queryKey] = query => {

src/Selector.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@ export class Selector extends Origin {
1616
lastIndex = args.length - 2;
1717
}
1818

19-
const testQueries = [];
20-
2119
const sources = args.slice(0, lastIndex);
20+
2221
const sourceIds = [];
23-
sources.forEach(source => {
24-
const hasQuery = !!source.source;
25-
sourceIds.push(hasQuery ? source.source._id : source._id);
26-
if (hasQuery) {
27-
testQueries.push(source.query);
28-
}
29-
});
22+
23+
const getTestQueries = sourcesOfLevel => {
24+
const queries = [];
25+
sourcesOfLevel.forEach(source => {
26+
if (isArray(source)) {
27+
queries.push(getTestQueries(source));
28+
} else {
29+
const hasQuery = !!source.source;
30+
sourceIds.push(hasQuery ? source.source._id : source._id);
31+
if (hasQuery) {
32+
queries.push(source.query);
33+
}
34+
}
35+
});
36+
return queries;
37+
};
38+
39+
const testQueries = getTestQueries(sources);
3040

3141
super(`select:${sourceIds.join(":")}`, defaultValue);
3242

0 commit comments

Comments
 (0)