Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Add Prettier (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Jun 27, 2018
1 parent e9bea61 commit 70cf95f
Show file tree
Hide file tree
Showing 38 changed files with 134 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "all"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"test": "lerna run test",
"build": "lerna run build",
"clean": "lerna clean"
"clean": "lerna clean",
"prettier": "lerna run prettier"
},
"workspaces": {
"packages": [
Expand Down
6 changes: 4 additions & 2 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"bundle": "rollup -c rollup.config.js",
"build": "ngc -p tsconfig.json",
"postbuild": "yarn bundle",
"prepublishOnly": "yarn build"
"prepublishOnly": "yarn build",
"prettier": "prettier --config ../../.prettierrc --write {src,tests}/**/*.ts"
},
"peerDependencies": {
"@angular/core": "^6.0.0",
Expand All @@ -41,6 +42,7 @@
"graphql-tag": "2.9.2",
"jest": "22.4.4",
"ng-packagr": "4.0.0-rc.1",
"prettier": "1.13.6",
"rollup": "0.61.2",
"rxjs": "6.2.1",
"ts-jest": "22.4.6",
Expand Down Expand Up @@ -72,4 +74,4 @@
"graphql",
"local"
]
}
}
6 changes: 3 additions & 3 deletions packages/angular/src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, OnDestroy } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import {Injectable, OnDestroy} from '@angular/core';
import {BehaviorSubject} from 'rxjs';

export const INIT: '@Init' = '@Init';

Expand All @@ -10,7 +10,7 @@ export class MutationAsAction {
@Injectable()
export class Actions extends BehaviorSubject<any> implements OnDestroy {
constructor() {
super({ type: INIT });
super({type: INIT});
}

complete() {}
Expand Down
18 changes: 9 additions & 9 deletions packages/angular/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@angular/core';
import { Apollo, QueryRef } from 'apollo-angular';
import { WatchQueryOptions } from 'apollo-client';
import { Observable, queueScheduler, of } from 'rxjs';
import { observeOn, mergeMap, mapTo } from 'rxjs/operators';

import { isMutation, getMutation, mutationToType } from './internal/mutation';
import { Actions } from './actions';
import { Dispatcher } from './internal/dispatcher';
import {Injectable} from '@angular/core';
import {Apollo, QueryRef} from 'apollo-angular';
import {WatchQueryOptions} from 'apollo-client';
import {Observable, queueScheduler, of} from 'rxjs';
import {observeOn, mergeMap, mapTo} from 'rxjs/operators';

import {isMutation, getMutation, mutationToType} from './internal/mutation';
import {Actions} from './actions';
import {Dispatcher} from './internal/dispatcher';

@Injectable({
providedIn: 'root',
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/decorators/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs';
import {Observable} from 'rxjs';

import { setActionMetadata } from '../metadata/action';
import {setActionMetadata} from '../metadata/action';

export function Action(actions: any | any[], options?: any) {
return function(
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/decorators/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DocumentNode } from 'graphql';
import {DocumentNode} from 'graphql';

import { setMutationMetadata } from '../metadata/mutation';
import { isMutation } from '../internal/mutation';
import {setMutationMetadata} from '../metadata/mutation';
import {isMutation} from '../internal/mutation';

export function Mutation(mutation: DocumentNode | any, options?: any) {
return function(
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/decorators/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setQueryMetadata } from '../metadata/query';
import {setQueryMetadata} from '../metadata/query';

export function Query() {
return function(
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/decorators/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setStateMetadata } from '../metadata/state';
import { StateOptions } from '../types/state';
import {setStateMetadata} from '../metadata/state';
import {StateOptions} from '../types/state';

export function State<T>(options: StateOptions<T>) {
return (target: any) => {
Expand Down
18 changes: 9 additions & 9 deletions packages/angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { Manager, LoonaLink, Update } from '@loona/core';
export {Manager, LoonaLink, Update} from '@loona/core';
// decorators
export { State } from './decorators/state';
export { Action } from './decorators/action';
export { Mutation } from './decorators/mutation';
export { Query } from './decorators/query';
export {State} from './decorators/state';
export {Action} from './decorators/action';
export {Mutation} from './decorators/mutation';
export {Query} from './decorators/query';
// providers
export { Actions, getActionType } from './actions';
export { Loona } from './client';
export { LoonaModule } from './module';
export { INITIAL_STATE, FEATURE_STATE, APOLLO_CACHE } from './tokens';
export {Actions, getActionType} from './actions';
export {Loona} from './client';
export {LoonaModule} from './module';
export {INITIAL_STATE, FEATURE_STATE, APOLLO_CACHE} from './tokens';
4 changes: 2 additions & 2 deletions packages/angular/src/internal/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import {Injectable, OnDestroy} from '@angular/core';
import {Subject} from 'rxjs';

@Injectable()
export class Dispatcher extends Subject<any> implements OnDestroy {
Expand Down
20 changes: 10 additions & 10 deletions packages/angular/src/internal/effects.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable, Inject, Injector } from '@angular/core';
import { Observable, forkJoin, from, of, throwError } from 'rxjs';
import { mergeMap, first } from 'rxjs/operators';
import {Injectable, Inject, Injector} from '@angular/core';
import {Observable, forkJoin, from, of, throwError} from 'rxjs';
import {mergeMap, first} from 'rxjs/operators';

import { Actions, getActionType } from '../actions';
import { Loona } from '../client';
import { INITIAL_STATE } from '../tokens';
import { StateClass } from '../types/state';
import { METADATA_KEY } from '../metadata/metadata';
import { isPromise, isObservable } from './utils';
import { isMutation } from '../internal/mutation';
import {Actions, getActionType} from '../actions';
import {Loona} from '../client';
import {INITIAL_STATE} from '../tokens';
import {StateClass} from '../types/state';
import {METADATA_KEY} from '../metadata/metadata';
import {isPromise, isObservable} from './utils';
import {isMutation} from '../internal/mutation';

@Injectable()
export class Effects {
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/internal/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentNode } from 'graphql';
import { getNameOfMutation } from '@loona/core';
import {DocumentNode} from 'graphql';
import {getNameOfMutation} from '@loona/core';

const prefix = '@@mutation: ';

Expand Down
10 changes: 5 additions & 5 deletions packages/angular/src/internal/transform-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { MutationDef, QueryDef } from '@loona/core';
import {MutationDef, QueryDef} from '@loona/core';

import { Metadata } from '../types/metadata';
import { createResolver } from './utils';
import {Metadata} from '../types/metadata';
import {createResolver} from './utils';

export function transformMutations(
instance: any,
meta: Metadata,
): MutationDef[] {
return meta.mutations.map(({ propName, mutation, options }) => ({
return meta.mutations.map(({propName, mutation, options}) => ({
mutation: mutation || options.mutation,
resolve: createResolver(instance, propName),
}));
}

export function transformQueries(instance: any, meta: Metadata): QueryDef[] {
return meta.queries.map(({ propName }) => ({
return meta.queries.map(({propName}) => ({
name: propName,
resolve: createResolver(instance, propName),
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable, from } from 'rxjs';
import { first } from 'rxjs/operators';
import {Observable, from} from 'rxjs';
import {first} from 'rxjs/operators';

function wrapObservable(instance: any, propName: string) {
return (...args: any[]) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/metadata/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ensureMetadata } from './metadata';
import { isMutation, mutationToType } from '../internal/mutation';
import {ensureMetadata} from './metadata';
import {isMutation, mutationToType} from '../internal/mutation';

export function setActionMetadata(
proto: any,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/metadata/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Metadata } from '../types/metadata';
import {Metadata} from '../types/metadata';

export const METADATA_KEY = '@@loona';

Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/metadata/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentNode } from 'graphql';
import {DocumentNode} from 'graphql';

import { ensureMetadata } from './metadata';
import {ensureMetadata} from './metadata';

export function setMutationMetadata(
proto: any,
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/metadata/query.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ensureMetadata } from './metadata';
import {ensureMetadata} from './metadata';

export function setQueryMetadata(proto: any, propName: string) {
const constructor = proto.constructor;
const meta = ensureMetadata(constructor);

meta.queries.push({ propName });
meta.queries.push({propName});
}
4 changes: 2 additions & 2 deletions packages/angular/src/metadata/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ensureMetadata } from './metadata';
import { StateOptions } from '../types/state';
import {ensureMetadata} from './metadata';
import {StateOptions} from '../types/state';

export function setStateMetadata(target: any, options?: StateOptions<any>) {
const meta = ensureMetadata(target);
Expand Down
28 changes: 14 additions & 14 deletions packages/angular/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { NgModule, ModuleWithProviders, Injector } from '@angular/core';
import { ApolloCache } from 'apollo-cache';
import { Manager, QueryDef, MutationDef, LoonaLink } from '@loona/core';
import {NgModule, ModuleWithProviders, Injector} from '@angular/core';
import {ApolloCache} from 'apollo-cache';
import {Manager, QueryDef, MutationDef, LoonaLink} from '@loona/core';

import { Loona } from './client';
import { Actions } from './actions';
import { Dispatcher } from './internal/dispatcher';
import { Effects } from './internal/effects';
import { INITIAL_STATE, FEATURE_STATE, APOLLO_CACHE } from './tokens';
import { StateClass } from './types/state';
import { METADATA_KEY } from './metadata/metadata';
import {Loona} from './client';
import {Actions} from './actions';
import {Dispatcher} from './internal/dispatcher';
import {Effects} from './internal/effects';
import {INITIAL_STATE, FEATURE_STATE, APOLLO_CACHE} from './tokens';
import {StateClass} from './types/state';
import {METADATA_KEY} from './metadata/metadata';
import {
transformQueries,
transformMutations,
} from './internal/transform-metadata';
import { isString } from './internal/utils';
import {isString} from './internal/utils';

@NgModule({
providers: [Loona, Dispatcher],
Expand Down Expand Up @@ -43,8 +43,8 @@ export class LoonaModule {
Actions,
Effects,
...states,
{ provide: APOLLO_CACHE, useValue: cache },
{ provide: INITIAL_STATE, useValue: states },
{provide: APOLLO_CACHE, useValue: cache},
{provide: INITIAL_STATE, useValue: states},
{
provide: LoonaLink,
useFactory: linkFactory,
Expand All @@ -62,7 +62,7 @@ export class LoonaModule {
static forFeature(states: any[] = []): ModuleWithProviders {
return {
ngModule: LoonaFeatureModule,
providers: [...states, { provide: FEATURE_STATE, useValue: states }],
providers: [...states, {provide: FEATURE_STATE, useValue: states}],
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InjectionToken } from '@angular/core';
import { ApolloCache } from 'apollo-cache';
import {InjectionToken} from '@angular/core';
import {ApolloCache} from 'apollo-cache';

import { StateClass } from './types/state';
import {StateClass} from './types/state';

export const INITIAL_STATE = new InjectionToken<StateClass>(
'[@loona/angular] State',
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/types/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { DocumentNode } from 'graphql';
import {DocumentNode} from 'graphql';

export namespace Metadata {
export type Queries = Array<{ propName: string }>;
export type Queries = Array<{propName: string}>;
export type Mutations = Array<{
propName: string;
mutation: DocumentNode;
options: any;
}>;
export type Actions = Record<
string,
Array<{ propName: string; type: string; options: any }>
Array<{propName: string; type: string; options: any}>
>;
export type Defaults = Record<string, any>;
export type TypeDefs = string | string[];
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/types/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { METADATA_KEY } from '../metadata/metadata';
import { Metadata } from '../types/metadata';
import {METADATA_KEY} from '../metadata/metadata';
import {Metadata} from '../types/metadata';

export interface StateClass {
[METADATA_KEY]: Metadata;
Expand Down
6 changes: 4 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"bundle": "rollup -c rollup.config.js",
"build": "tsc -p tsconfig.json",
"postbuild": "yarn bundle",
"prepublishOnly": "yarn build"
"prepublishOnly": "yarn build",
"prettier": "prettier --config ../../.prettierrc --write {src,tests}/**/*.ts"
},
"peerDependencies": {
"graphql": "^0.13.2"
Expand All @@ -32,6 +33,7 @@
"graphql": "0.13.2",
"graphql-tag": "2.9.2",
"jest": "22.4.4",
"prettier": "1.13.6",
"rollup": "0.61.2",
"ts-jest": "22.4.6",
"typescript": "2.9.1"
Expand All @@ -53,4 +55,4 @@
"js"
]
}
}
}
10 changes: 5 additions & 5 deletions packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { DocumentNode } from 'graphql';
import { DataProxy } from 'apollo-cache';
import {DocumentNode} from 'graphql';
import {DataProxy} from 'apollo-cache';
import produce from 'immer';

import { getMutationDefinition, getFirstField } from './internal/utils';
import {getMutationDefinition, getFirstField} from './internal/utils';

export function updateQuery<S = any, A = any, C = any>(
query: DocumentNode,
fn: (val: S, args: A, ctx: C) => S | void,
) {
return (_root: any, args: A, context: C) => {
const cache: DataProxy = (context as any).cache;
const previous = cache.readQuery<S>({ query }) as S;
const previous = cache.readQuery<S>({query}) as S;

const data = produce<S>(previous, draft => fn(draft, args, context));

cache.writeQuery({ query, data });
cache.writeQuery({query, data});

return null;
};
Expand Down
Loading

0 comments on commit 70cf95f

Please sign in to comment.