Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from data-provider/v1.3.0
Browse files Browse the repository at this point in the history
V1.3.0
  • Loading branch information
javierbrea authored Nov 23, 2019
2 parents 1bf25f2 + 6109691 commit 55a3816
Show file tree
Hide file tree
Showing 94 changed files with 1,338 additions and 319 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ cache:

addons:
sonarcloud:
organization: "javierbrea"
token:
secure: "$SONAR_TOKEN"
organization: "data-provider"
branch:
name: "$TRAVIS_CURRENT_BRANCH"

Expand All @@ -21,11 +19,11 @@ script:
- npm run test-ci
- npm run build
- npm run coveralls
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sonar-scanner; fi'
- 'if [ -n "$SONAR_TOKEN" ]; then sonar-scanner -Dsonar.login=${SONAR_TOKEN}; fi'

deploy:
provider: npm
email: "devops@xbyorange.com"
email: "javier.brea@gmail.com"
api_key: "$NPM_TOKEN"
on:
tags: true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [1.3.0] - 2019-11-23
### Changed
- Project migration. __Read NOTICE__ for further info. All previous releases in this CHANGELOG file correspond to @xbyorange/react-mercury package distribution.

## [1.2.1] - 2019-10-22
### Fixed
- Do not throw an error on duplicated ids detected while reading server side data.
Expand Down
15 changes: 2 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,5 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2019 Javier Brea
Copyright 2019 XbyOrange
6 changes: 6 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data-provider react connector
Copyright 2019 Javier Brea

Portions of this software were developed at XbyOrange company.
Forked from XByOrange React Mercury v1.2.1, distributed under The Apache Software License, Version 2.0.
Github repository "xbyorange/react-mercury" (https://github.com/XbyOrange/react-mercury), branch master, commit bb637d0f11391aa377d6b6c0c4bb9d6108fd35a3. The original project files were wrongly licensed because an error of the main maintainer, Javier Brea, who received instructions from the XbyOrange company about licensing it as Apache2.0, but didn't include the appropiate license header in all repository files by error. The error has been fixed and XbyOrange license headers have been added to all original files, as it was the real intention of the XbyOrange company.
78 changes: 38 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@

[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![License][license-image]][license-url]

# ![Mercury Logo](assets/logos/mercury_wings_orange_100.png) React Mercury

## Overview

This package provides reactivity to [Mercury data][mercury-url] using a React high order component. It also dispatchs automatically the read method of the Mercury sources.
This package provides reactivity to [Data Provider][data-provider-url] using a React high order component. It also dispatchs automatically the read method of the Data Provider sources.

Connect the desired sources with your components and this library will retrieve the data and re-render your components when corresponds.

## Install

```bash
npm i @xbyorange/react-mercury --save
npm i @data-provider/connector-react --save
```

## Examples

In the next example, the books will be retrieved automatically from server if they are not cached. The component will be rendered again if a new book is added to the collection by another component, or deleted, etc.

Components can be connected to [Mercury origins or selectors][mercury-url]. The interface is the same in all cases.
Components can be connected to [Data Provider origins or selectors][data-provider-url]. The interface is the same in all cases.

### Use connect

```jsx
import React, { Component } from "react";
import { connect } from "@xbyorange/react-mercury";
import { connect } from "@data-provider/connector-react";

import { booksCollection } from "data/books"; //booksCollection is a Mercury origin
import { booksCollection } from "data/books"; //booksCollection is a Data Provider origin

export class Books extends Component {
render() {
Expand Down Expand Up @@ -68,7 +66,7 @@ export const ConnectedBooks = connect(mapDataSourceToProps)(Books);

```

### Querying Mercury sources using component "props"
### Querying Data Provider sources using component "props"

In the next example, the component will render only books of author "cervantes", and will request them to the server using the correspondant query (if not cached previously):

Expand All @@ -80,7 +78,7 @@ export const mapDataSourceToProps = props => ({
export const ConnectedModule = connect(mapDataSourceToProps)(Books);
```

### Connect component to many Mercury sources
### Connect component to many Data Provider sources

The connect function accepts connecting as many sources as you want. Any change on any of the sources will produce a new render of the component:

Expand All @@ -93,12 +91,12 @@ export const mapDataSourceToProps = () => ({
export const ConnectedModule = connect(mapDataSourceToProps)(Books);
```

### Connect component to specific properties of a Mercury source
### Connect component to specific properties of a Data Provider source

You can use the property getters available in sources to pass an specific property to components instead of the full object. This will improve and simplify the usage of props inside the component, because each component prop will be equivalent to an specific source property:

```jsx
import { connect } from "@xbyorange/react-mercury";
import { connect } from "@data-provider/connector-react";

export const BooksList = ({ books, booksLoading, booksError }) => {
if(booksError) {
Expand Down Expand Up @@ -132,7 +130,7 @@ export const ConnectedModule = connect(mapDataSourceToProps)(BooksList);

### Pass any other type of properties using connect:

The connect function can pass any other types of properties to the Component, not only Mercury sources:
The connect function can pass any other types of properties to the Component, not only Data Provider sources:

```js
export const mapDataSourceToProps = props => ({
Expand Down Expand Up @@ -175,38 +173,38 @@ export const ConnectedModule = connect(
)(Books);
```

> This parser function should not be used as a replacement to Mercury Selectors. As a good practice, the preference is to use Selectors if possible instead of this function.
> This parser function should not be used as a replacement to Data Provider Selectors. As a good practice, the preference is to use Selectors if possible instead of this function.
## Prefetching data on server side rendering

Methods for prefetching data on server side rendering are available too. When data is prefetched in server side, the connect function will pass the `value` property calculated on server side to the components directly. It will not modify the `loading` property until the first load on client side is finished (At first client-side load, the resource will not be considered as `loading` to maintain the server-side value in the component until it finish loading).

> __It is important to define custom an unique "uuids" for your mercury sources when are going to be read on server side. Otherwise, the `readServerSide` method will trace a warning if detects duplicated "ids".__
> __It is important to define custom an unique "uuids" for your Data Provider sources when are going to be read on server side. Otherwise, the `readServerSide` method will trace a warning if detects duplicated "ids".__
### Server side data methods and components

* `readOnServerSide(source)`
* Alias - `addServerSideData`
* Arguments
* source - `<Object> or <Array> of <Objects>` Mercury source or sources that should be read when `readServerSide` method is executed. Can be Mercury origins or selectors of any type, queried or not.
* source - `<Object> or <Array> of <Objects>` Data Provider source or sources that should be read when `readServerSide` method is executed. Can be Data Provider origins or selectors of any type, queried or not.
* `readServerSide([source])`
* Alias - `readServerSideData`
* Arguments
* source - `<Object> or <Array> of <Objects>` Mercury source or sources. Will be added to be read with the `readOnServerSide` method.
* source - `<Object> or <Array> of <Objects>` Data Provider source or sources. Will be added to be read with the `readOnServerSide` method.
* Returns
* `<Object>` This method is asynchronous, and, when resolved, it returns an object containing all server side data ready to be set on the `<ServerSideData>` context component.
* `<ServerSideData data={data} clientSide={true}><App/></ServerSideData>` Component that sets the result of the `readServerSide` method in a context to make it available from all mercury connected children components.
* `<ServerSideData data={data} clientSide={true}><App/></ServerSideData>` Component that sets the result of the `readServerSide` method in a context to make it available from all Data Provider connected children components.
* Props
* data - `<Object>` Object containing the result of the `readServerSide` method.
* clientSide - `<Boolean>` If false, the connect method will not dispatch automatically the read method of the sources marked as "server-side", so, for example, api requests will not be repeated on client side, and data retrieved in server side will be always passed to connected components.

### Example of server side prefecth implementation in a Next project:

In the next example, the data of the "myDataSource" mercury source will be fetched on server side and request will not be repeated on client side. The component will be rendered directly with server side data, and no loading state will be set:
In the next example, the data of the "myDataSource" Data Provider source will be fetched on server side and request will not be repeated on client side. The component will be rendered directly with server side data, and no loading state will be set:

```jsx
// src/home.js
import { readOnServerSide, connect } from "@xbyorange/react-mercury";
import { readOnServerSide, connect } from "@data-provider/connector-react";
import { myDataSource } from "src/data";

readOnServerSide(myDataSource); // source is marked to be read when readServerSide method is executed.
Expand All @@ -228,7 +226,7 @@ export const Home = connect(mapDataSourceToProps)(HomeComponent)

```jsx
// pages/index.js
import { readServerSide, ServerSideData } from "@xbyorange/react-mercury";
import { readServerSide, ServerSideData } from "@data-provider/connector-react";
import { Home } from "src/home";

const Page = ({ serverSideData }) => (
Expand All @@ -251,8 +249,8 @@ export default Page;
To run a real implementation example in a React app, you can clone the project and execute the provided demo:

```bash
git clone git@github.com:XbyOrange/react-mercury.git
cd react-mercury
git clone git@github.com:data-provider/connector-react.git
cd connector-react
npm i
npm run build
cd demo
Expand All @@ -274,21 +272,21 @@ npm start
Contributors are welcome.
Please read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).

[mercury-url]: https://github.com/xbyorange/mercury

[coveralls-image]: https://coveralls.io/repos/github/XbyOrange/react-mercury/badge.svg
[coveralls-url]: https://coveralls.io/github/XbyOrange/react-mercury
[travisci-image]: https://travis-ci.com/xbyorange/react-mercury.svg?branch=master
[travisci-url]: https://travis-ci.com/xbyorange/react-mercury
[last-commit-image]: https://img.shields.io/github/last-commit/xbyorange/react-mercury.svg
[last-commit-url]: https://github.com/xbyorange/react-mercury/commits
[license-image]: https://img.shields.io/npm/l/@xbyorange/react-mercury.svg
[license-url]: https://github.com/xbyorange/react-mercury/blob/master/LICENSE
[npm-downloads-image]: https://img.shields.io/npm/dm/@xbyorange/react-mercury.svg
[npm-downloads-url]: https://www.npmjs.com/package/@xbyorange/react-mercury
[npm-dependencies-image]: https://img.shields.io/david/xbyorange/react-mercury.svg
[npm-dependencies-url]: https://david-dm.org/xbyorange/react-mercury
[quality-gate-image]: https://sonarcloud.io/api/project_badges/measure?project=xbyorange-react-mercury&metric=alert_status
[quality-gate-url]: https://sonarcloud.io/dashboard?id=xbyorange-react-mercury
[release-image]: https://img.shields.io/github/release-date/xbyorange/react-mercury.svg
[release-url]: https://github.com/xbyorange/react-mercury/releases
[data-provider-url]: https://github.com/data-provider/core

[coveralls-image]: https://coveralls.io/repos/github/data-provider/connector-react/badge.svg
[coveralls-url]: https://coveralls.io/github/data-provider/connector-react
[travisci-image]: https://travis-ci.com/data-provider/connector-react.svg?branch=master
[travisci-url]: https://travis-ci.com/data-provider/connector-react
[last-commit-image]: https://img.shields.io/github/last-commit/data-provider/connector-react.svg
[last-commit-url]: https://github.com/data-provider/connector-react/commits
[license-image]: https://img.shields.io/npm/l/@data-provider/connector-react.svg
[license-url]: https://github.com/data-provider/connector-react/blob/master/LICENSE
[npm-downloads-image]: https://img.shields.io/npm/dm/@data-provider/connector-react.svg
[npm-downloads-url]: https://www.npmjs.com/package/@data-provider/connector-react
[npm-dependencies-image]: https://img.shields.io/david/data-provider/connector-react.svg
[npm-dependencies-url]: https://david-dm.org/data-provider/connector-react
[quality-gate-image]: https://sonarcloud.io/api/project_badges/measure?project=data-provider-connector-react&metric=alert_status
[quality-gate-url]: https://sonarcloud.io/dashboard?id=data-provider-connector-react
[release-image]: https://img.shields.io/github/release-date/data-provider/connector-react.svg
[release-url]: https://github.com/data-provider/connector-react/releases
Binary file removed assets/logos/mercury_wings_orange_100.png
Binary file not shown.
2 changes: 1 addition & 1 deletion demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/node_modules
/.pnp
.pnp.js
/src/react-mercury
/src/connector-react

# testing
/coverage
Expand Down
16 changes: 14 additions & 2 deletions demo/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
Copyright 2019 Javier Brea
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

module.exports = function override(config) {
// Remove eslint execution for running app
let eslintRuleIndex;
Expand All @@ -14,7 +25,7 @@ module.exports = function override(config) {
config.module.rules.splice(eslintRuleIndex, 1);
}

// Add babel alias for react-mercury
// Add babel alias for data-provider/connector-react
config.module.rules.unshift({
test: /\.(js|jsx|mjs)$/,
include: /src/,
Expand All @@ -26,7 +37,8 @@ module.exports = function override(config) {
{
root: ["."],
alias: {
"@xbyorange/react-mercury": "./src/react-mercury/react-mercury.esm.js"
"@data-provider/connector-react":
"./src/connector-react/data-provider-connector-react.esm.js"
}
}
]
Expand Down
13 changes: 12 additions & 1 deletion demo/mocks/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
const { Feature } = require("@xbyorange/mocks-server");
/*
Copyright 2019 Javier Brea
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const { Feature } = require("@mocks-server/main");

const { getBooks, getBook, addBook, updateBook, deleteBook } = require("./fixtures/api/books");
const { getAuthors } = require("./fixtures/api/authors");
Expand Down
10 changes: 10 additions & 0 deletions demo/mocks/fixtures/api/author-books.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const booksByAuthor = {
"1": ["3"],
"2": ["1"],
Expand Down
10 changes: 10 additions & 0 deletions demo/mocks/fixtures/api/authors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const authors = new Set();

authors.add({
Expand Down
10 changes: 10 additions & 0 deletions demo/mocks/fixtures/api/books.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const books = new Set();

books.add({
Expand Down
10 changes: 10 additions & 0 deletions demo/mocks/fixtures/api/mobile-desktop.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const dataMobile = [
["mobile data 1", "mobile data 2"],
["mobile data 3", "mobile data 4"],
Expand Down
Loading

0 comments on commit 55a3816

Please sign in to comment.