Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Implement plugin #10

Merged
merged 19 commits into from
Jan 20, 2018
Merged
Show file tree
Hide file tree
Changes from 16 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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Installation

### Package

First clone and build Relay packages:

```
git clone https://github.com/alloy/relay.git -b language-plugin
cd relay
yarn install
yarn build
cd dist/babel-plugin-relay && npm pack
cd dist/react-relay && npm pack
cd dist/relay-compiler && npm pack
cd dist/relay-runtime && npm pack
cd dist/relay-test-utils && npm pack
cd ..
```

Then setup package:

```
git clone https://github.com/kastermester/relay-compiler-language-typescript.git
cd relay-compiler-language-typescript
yarn install
```

### Example

After following the above package steps:

```
npm pack
cd example
yarn install
yarn build
yarn start
```
12 changes: 12 additions & 0 deletions example/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"passPerPreset": true,
"plugins": [
"relay",
"transform-runtime"
],
"presets": [
"react",
"es2015",
"stage-0"
]
}
1 change: 1 addition & 0 deletions example/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__generated__/
4 changes: 4 additions & 0 deletions example/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

extends:
- fbjs
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
__generated__/
Empty file added example/.watchmanconfig
Empty file.
48 changes: 48 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Relay TodoMVC

## Installation

```
npm install
```

## Running

Set up generated files:

```
npm run update-schema
npm run build
```

Start a local server:

```
npm start
```

## Developing

Any changes you make to files in the `js/` directory will cause the server to
automatically rebuild the app and refresh your browser.

If at any time you make changes to `data/schema.js`, stop the server,
regenerate `data/schema.graphql`, and restart the server:

```
npm run update-schema
npm run build
npm start
```

## License

This file provided by Facebook is for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
98 changes: 98 additions & 0 deletions example/data/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* This file provided by Facebook is for non-commercial testing and evaluation
* purposes only. Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

export class Todo {}
export class User {}

// Mock authenticated ID
const VIEWER_ID = 'me';

// Mock user data
const viewer = new User();
viewer.id = VIEWER_ID;
const usersById = {
[VIEWER_ID]: viewer,
};

// Mock todo data
const todosById = {};
const todoIdsByUser = {
[VIEWER_ID]: [],
};
let nextTodoId = 0;
addTodo('Taste JavaScript', true);
addTodo('Buy a unicorn', false);

export function addTodo(text, complete) {
const todo = new Todo();
todo.complete = !!complete;
todo.id = `${nextTodoId++}`;
todo.text = text;
todosById[todo.id] = todo;
todoIdsByUser[VIEWER_ID].push(todo.id);
return todo.id;
}

export function changeTodoStatus(id, complete) {
const todo = getTodo(id);
todo.complete = complete;
}

export function getTodo(id) {
return todosById[id];
}

export function getTodos(status = 'any') {
const todos = todoIdsByUser[VIEWER_ID].map(id => todosById[id]);
if (status === 'any') {
return todos;
}
return todos.filter(todo => todo.complete === (status === 'completed'));
}

export function getUser(id) {
return usersById[id];
}

export function getViewer() {
return getUser(VIEWER_ID);
}

export function markAllTodos(complete) {
const changedTodos = [];
getTodos().forEach(todo => {
if (todo.complete !== complete) {
todo.complete = complete;
changedTodos.push(todo);
}
});
return changedTodos.map(todo => todo.id);
}

export function removeTodo(id) {
const todoIndex = todoIdsByUser[VIEWER_ID].indexOf(id);
if (todoIndex !== -1) {
todoIdsByUser[VIEWER_ID].splice(todoIndex, 1);
}
delete todosById[id];
}

export function removeCompletedTodos() {
const todosToRemove = getTodos().filter(todo => todo.complete);
todosToRemove.forEach(todo => removeTodo(todo.id));
return todosToRemove.map(todo => todo.id);
}

export function renameTodo(id, text) {
const todo = getTodo(id);
todo.text = text;
}
File renamed without changes.
Loading