Skip to content

Commit

Permalink
Merge pull request #10 from XbyOrange/v1.1.0
Browse files Browse the repository at this point in the history
V1.1.0
  • Loading branch information
javierbrea authored Jun 28, 2019
2 parents 1d02d25 + cae3b06 commit 239a3e8
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 152 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [1.1.0] - 2019-06-25
### Added
- Expose `_root` property in queried instances to allow identify the root instance.
- Emit `_root` property on cleanAny events.

### Fixed
- Expose custom queries methods in `customQueries` property, as described in documentation.
- Expose test.queries properties for concurrent sources.

## [1.0.0] - 2019-06-03
### BREAKING CHANGES
- Forked from xByOrange reactive-data-source v1.7.0 private library. (Only Origin and Selector are exposed from now)
Expand Down
13 changes: 1 addition & 12 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,7 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2019 XByOrange

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xbyorange/mercury",
"version": "1.0.0",
"version": "1.1.0",
"description": "Mercury. Reactive CRUD data layer",
"keywords": [
"reactive",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=javierbrea
sonar.projectKey=xbyorange-mercury
sonar.projectVersion=1.0.0
sonar.projectVersion=1.1.0

sonar.sources=src,test
sonar.exclusions=node_modules/**
Expand Down
11 changes: 6 additions & 5 deletions src/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ export class Cache {
});
}

getAnyData(queryUniqueId) {
getAnyData(queryUniqueId, _root) {
return {
action: "clean",
source: {
_id: `${this._id}${queryUniqueId ? `-${queryUniqueId}` : ""}`,
_queryId: queryUniqueId
_queryId: queryUniqueId,
_root
}
};
}

clean(query) {
clean(query, _root) {
if (query) {
const queryIdentifier = queryId(query);
delete this._cachedData[queryIdentifier];
this._eventEmitter.emit(cleanCacheEventName(query), query);
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(queryIdentifier));
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(queryIdentifier, _root));
} else {
this._reset();
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData());
this._eventEmitter.emit(CLEAN_ANY_EVENT_NAME, this.getAnyData(null, _root));
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/Origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Origin {
typeof defaultValue !== "undefined" ? cloneDeep(defaultValue) : defaultValue;

this._customQueries = {};
this.customQueries = {};
this.test = {};

this._createBaseMethods();
Expand Down Expand Up @@ -82,10 +83,10 @@ export class Origin {
}

_clean(query) {
this._cache.clean(query);
this._cache.clean(query, this);
}

_createQueryMethods(query, queryId) {
_createQueryMethods(query, id) {
const methods = {};

const updateData = (data, methodName, action, params) => {
Expand All @@ -106,7 +107,7 @@ export class Origin {
methods[methodName].error = newData.error;
this._emitChange(query, methodName);
this._emitChangeAny({
source: this._queries[queryId],
source: this._queries[id],
method: methodName,
action,
params
Expand Down Expand Up @@ -219,8 +220,10 @@ export class Origin {
newQuery._id = `${this._id}${queryUniqueId ? `-${queryUniqueId}` : ""}`;
newQuery.actions = actions;
newQuery._isSource = true;
newQuery._root = this;

newQuery.query = queryExtension => this.query(merge(query, queryExtension));
newQuery.customQueries = this._customQueries;

Object.keys(this._customQueries).forEach(queryKey => {
newQuery[queryKey] = queryExtension => {
Expand All @@ -236,6 +239,7 @@ export class Origin {
addCustomQueries(customQueries) {
Object.keys(customQueries).forEach(queryKey => {
this._customQueries[queryKey] = customQueries[queryKey];
this.customQueries[queryKey] = customQueries[queryKey];
this.test.customQueries = this.test.customQueries || {};
this.test.customQueries[queryKey] = customQueries[queryKey];
this[queryKey] = query => {
Expand Down
28 changes: 19 additions & 9 deletions src/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ export class Selector extends Origin {
lastIndex = args.length - 2;
}

const testQueries = [];

const sources = args.slice(0, lastIndex);

const sourceIds = [];
sources.forEach(source => {
const hasQuery = !!source.source;
sourceIds.push(hasQuery ? source.source._id : source._id);
if (hasQuery) {
testQueries.push(source.query);
}
});

const getTestQueries = sourcesOfLevel => {
const queries = [];
sourcesOfLevel.forEach(source => {
if (isArray(source)) {
queries.push(getTestQueries(source));
} else {
const hasQuery = !!source.source;
sourceIds.push(hasQuery ? source.source._id : source._id);
if (hasQuery) {
queries.push(source.query);
}
}
});
return queries;
};

const testQueries = getTestQueries(sources);

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

Expand Down
Loading

0 comments on commit 239a3e8

Please sign in to comment.