Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/add versioning in docusaurus #415

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions documentation/website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,74 @@
"getting-started": {
"title": "Getting Started",
"sidebar_label": "Getting Started"
},
"version-6.x-canary/api/version-6.x-canary-accumulator": {
"title": "Accumulator",
"sidebar_label": "Accumulator"
},
"version-6.x-canary/api/version-6.x-canary-basic-examples": {
"title": "Examples",
"sidebar_label": "Examples"
},
"version-6.x-canary/api/version-6.x-canary-data-point": {
"title": "DataPoint",
"sidebar_label": "DataPoint"
},
"version-6.x-canary/api/version-6.x-canary-reducer-types": {
"title": "Reducers Types",
"sidebar_label": "Reducers Types"
},
"version-6.x-canary/api/reducers/version-6.x-canary-assign-reducer": {
"title": "AssignReducer",
"sidebar_label": "AssignReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-entity-reducer": {
"title": "EntityReducer Class",
"sidebar_label": "EntityReducer Class"
},
"version-6.x-canary/api/reducers/version-6.x-canary-fallback-reducer": {
"title": "FallbackReducer",
"sidebar_label": "FallbackReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-function-reducer": {
"title": "FunctionReducer",
"sidebar_label": "FunctionReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-if-then-else-reducer": {
"title": "IfThenElseReducer",
"sidebar_label": "IfThenElseReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-list-reducer": {
"title": "ListReducer",
"sidebar_label": "ListReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-map-reducer": {
"title": "MapReducer",
"sidebar_label": "MapReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-model": {
"title": "Model",
"sidebar_label": "Model"
},
"version-6.x-canary/api/reducers/version-6.x-canary-object-reducer": {
"title": "ObjectReducer",
"sidebar_label": "ObjectReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-parallel-reducer": {
"title": "ParallelReducer",
"sidebar_label": "ParallelReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-path-reducer": {
"title": "PathReducer",
"sidebar_label": "PathReducer"
},
"version-6.x-canary/api/reducers/version-6.x-canary-select-reducer": {
"title": "SelectReducer",
"sidebar_label": "SelectReducer"
},
"version-6.x-canary/version-6.x-canary-getting-started": {
"title": "Getting Started",
"sidebar_label": "Getting Started"
}
},
"links": {
Expand Down
6 changes: 5 additions & 1 deletion documentation/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"generate-jsdoc": "yarn jsdoc -r --destination static/jsdoc -c jsdoc.json ../../packages/data-point/src/ ./README.md",
"publish-gh-pages": "yarn generate-jsdoc; docusaurus-publish",
"start": "yarn generate-jsdoc; docusaurus-start",
"build": "yarn generate-jsdoc; docusaurus-build"
"build": "yarn generate-jsdoc; docusaurus-build",
"version": "yarn generate-jsdoc; docusaurus-version",
"examples": "yarn generate-jsdoc; docusaurus-examples",
"rename-version": "yarn generate-jsdoc; docusaurus-rename-version",
"write-translations": "yarn generate-jsdoc; docusaurus-write-translations",
},
"devDependencies": {
"docdash": "^1.1.1",
Expand Down
120 changes: 120 additions & 0 deletions documentation/website/pages/en/versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const React = require("react");

const CompLibrary = require("../../core/CompLibrary");

const Container = CompLibrary.Container;

const CWD = process.cwd();

const versions = require(`${CWD}/versions.json`);

function Versions(props) {
const { config: siteConfig } = props;
const latestVersion = versions[0];
const repoUrl = `https://github.com/${siteConfig.organizationName}/${siteConfig.projectName}`;
return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer versionsContainer">
<div className="post">
<header className="postHeader">
<h1>{siteConfig.title} Versions</h1>
</header>
<h3 id="latest">Current version (Stable)</h3>
<table className="versions">
<tbody>
<tr>
<th>{latestVersion}</th>
<td>
{/* You are supposed to change this href where appropriate
Example: href="<baseUrl>/docs(/:language)/:id" */}
<a
href={`${siteConfig.baseUrl}${siteConfig.docsUrl}/${
props.language ? props.language + "/" : ""
}getting-started`}
>
Documentation
</a>
</td>
<td>
<a href="">Release Notes</a>
</td>
</tr>
</tbody>
</table>
<p>
This is an unpublish canary version, in progress and expectedly
unstable. You can find the latest stable version on{" "}
<a href={repoUrl}>GitHub</a>.
</p>
{/*
<h3 id="rc">Pre-release versions</h3>
<table className="versions">
<tbody>
<tr>
<th>master</th>
<td>
{ / * You are supposed to change this href where appropriate
Example: href="<baseUrl>/docs(/:language)/next/:id" * / }
<a
href={`${siteConfig.baseUrl}${siteConfig.docsUrl}/${
props.language ? props.language + '/' : ''
}next/doc1`}>
Documentation
</a>
</td>
<td>
<a href={repoUrl}>Source Code</a>
</td>
</tr>
</tbody>
</table>
*/}
<p>Other text describing this section.</p>
<h3 id="archive">Past Versions</h3>
<p>Here you can find previous versions of the documentation.</p>
<table className="versions">
<tbody>
{versions.map(
version =>
version !== latestVersion && (
<tr>
<th>{version}</th>
<td>
{/* You are supposed to change this href where appropriate
Example: href="<baseUrl>/docs(/:language)/:version/:id" */}
<a
href={`${siteConfig.baseUrl}${siteConfig.docsUrl}/${
props.language ? props.language + "/" : ""
}${version}/getting-started`}
>
Documentation
</a>
</td>
<td>
<a href={`${repoUrl}/releases/tag/v${version}`}>
Release Notes
</a>
</td>
</tr>
)
)}
</tbody>
</table>
<p>
You can find past versions of this project on{" "}
<a href={repoUrl}>GitHub</a>.
</p>
</div>
</Container>
</div>
);
}

module.exports = Versions;
10 changes: 7 additions & 3 deletions documentation/website/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ const siteConfig = {
headerLinks: [
{ doc: "getting-started", label: "Docs" },
{ href: "/data-point/jsdoc", label: "API" },
{ href: "https://github.com/ViacomInc/data-point", label: "GitHub", target: "_blank" }
{
href: "https://github.com/ViacomInc/data-point",
label: "GitHub",
target: "_blank"
}
],
separateCss: ['static/jsdoc/styles'],
separateCss: ["static/jsdoc/styles"],

/* path to images for header/footer */
headerIcon: "img/favicon.ico",
Expand All @@ -42,7 +46,7 @@ const siteConfig = {

/* Colors for website */
colors: {
primaryColor: "#250e23",
primaryColor: "#6d426d",
secondaryColor: "#190918"
},

Expand Down
Binary file modified documentation/website/static/img/favicon.ico
100755 → 100644
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: version-6.x-canary-accumulator
title: Accumulator
sidebar_label: Accumulator
original_id: accumulator
---

This object is passed to [reducers](reducer-types.md) and cache callbacks; it has contextual information about the current transformation being resolved.

Access to the accumulator object is made available through a [FunctionReducer](reducers/function-reducer).

The `accumulator.value` property is the current **input data** being passed to the reducer. This property should be treated as a **read-only immutable object** which will ensure that your reducers are [pure functions](https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-pure-function-d1c076bec976#.r4iqvt9f0) that produce no side effects.

**Properties exposed:**

| Key | Type | Description |
| :-------- | :------- | :------------------------------------------------------------------------------------------------------------ |
| _value_ | `Object` | Value to be transformed. |
| _locals_ | `Object` | Value passed from the `options` _argument_ when executing [dataPoint.resolve()](data-point#datapointresolve). |
| _reducer_ | `Object` | Information relative to the current [Reducer](reducer-types.md) being executed. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
id: version-6.x-canary-basic-examples
title: Examples
sidebar_label: Examples
original_id: basic-examples
---

## Hello World

Trivial example of transforming a given **input** with a [function reducer](#function-reducer).

```js
const { DataPoint } = require("data-point");

const sayHello = input => {
return `${input} World`;
};

const dataPoint = DataPoint();

dataPoint.resolve("Hello", reducer).then(output => {
// 'Hello World'
console.log(output);
});
```

## Fetching and agregation

Based on an initial feed, fetch and aggregate results from multiple remote services.

```js
const DataPoint = require("data-point");

// create DataPoint instance
const dataPoint = DataPoint.create();

const { Request, Model, Schema, map } = DataPoint;

// schema to verify data input
const PlanetSchema = Schema("PlanetSchema", {
schema: {
type: "object",
properties: {
planetId: {
$id: "/properties/planet",
type: "integer"
}
}
}
});

// remote service request
const PlanetRequest = Request("Planet", {
// {value.planetId} injects the
// value from the accumulator
// creates: https://swapi.co/api/planets/1/
url: "https://swapi.co/api/planets/{value.planetId}"
});

const ResidentRequest = Request("Resident", {
// check input is string
inputType: "string",
url: "{value}"
});

// model entity to resolve a Planet
const ResidentModel = Model("Resident", {
inputType: "string",
value: [
// hit request:Resident
ResidentRequest,
// extract data
{
name: "$name",
gender: "$gender",
birthYear: "$birth_year"
}
]
});

// model entity to resolve a Planet
const PlanetModel = Model("Planet", {
inputType: PlanetSchema,
value: [
// hit request:Planet data source
PlanetRequest,
// map result to an object reducer
{
// map name key
name: "$name",
population: "$population",
// residents is an array of urls
// eg. https://swapi.co/api/people/1/
// where each url gets mapped
// to a model:Resident
residents: ["$residents", map(ResidentModel)]
}
]
});

const input = {
planetId: 1
};

dataPoint.resolve(PlanetModel, input).then(output => {
console.log(output);
/*
output ->
{
name: 'Tatooine',
population: 200000,
residents:
[
{ name: 'Luke Skywalker', gender: 'male', birthYear: '19BBY' },
{ name: 'C-3PO', gender: 'n/a', birthYear: '112BBY' },
{ name: 'Darth Vader', gender: 'male', birthYear: '41.9BBY' },
...
]
}
*/
});
```
Loading