Skip to content

Instantly share code, notes, and snippets.

View kamilkisiela's full-sized avatar
🕶️
Kamil Kisiela

Kamil Kisiela kamilkisiela

🕶️
Kamil Kisiela
View GitHub Profile
import {state} from '@loona/react';
@state()
export class BooksState {}
import {state} from '@loona/react';
@state({
defaults: {
books: []
}
})
export class BooksState {}
import { mutation } from '@loona/react';
export class BooksState {
@mutation('addBook')
addBook(args, context) {
// our new book
const book = {
id: generateRandomId(),
title: args.title,
__typename: 'Book',
export class AddBook {
static type = '[Books] Add';
constructor(public title: string) {}
}
//
// Using Action component
//
import { Action } from '@loona/react';
export const NewBook = () => (
<Action>
{dispatch => (
<button onClick={() => dispatch(new AddBook('Harry Potter'))}>
import {effect} from '@loona/react';
export class BooksState {
@effect(AddBook)
bookAdded(action, context) {
console.log(action);
// outputs:
// {
// type: '[Books] Add',
// title: '...'
export class BooksState {
// It does nothing except creating a new book
@mutation('addBook')
addBook(args, context) {
return {
id: generateRandomId(),
title: args.title,
__typename: 'Book',
};
}
import { createLoona, LoonaProvider } from '@loona/react';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
// Instance of a cache
const cache = new InMemoryCache();
// Create Loona Link
new GraphQLObjectType({
name: 'Post',
fields: {
id: {
type: GraphQLString
},
text: {
type: GraphQLString
}
}
type Post {
id: String
text: String
}