Skip to content

Commit

Permalink
fix(observable): change styles for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Igmat committed Jun 9, 2019
1 parent c2b5004 commit 49ce52f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/observable/src/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export function getAtomCreator(obj: Function | object) {
return existingAtom !== undefined
? existingAtom
: objAtoms[p] = {
source: obj,
name: p,
dependencies: [],
dependents: [],
isDirty: true,
name: p,
source: obj,
value,
};
};
Expand Down
1 change: 0 additions & 1 deletion packages/observable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { autorun, IAutorunOptions } from './autorun';
export { ITransaction } from './mutations';
export { Observable } from './Observable';
export { observe } from './observe';

31 changes: 16 additions & 15 deletions packages/observable/src/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getAtomCreator } from './atoms';
import { calculate, linkToCalculated, recalculate } from './calculations';
import { ITransaction, mutate } from './mutations';
import { Observable } from './Observable';
// tslint:disable: no-unsafe-any

export function observeFunction<T extends Function>(fn: T, onSet?: (tx: ITransaction) => void) {
const createAtomIfNotExists = getAtomCreator(fn);
Expand All @@ -24,13 +25,6 @@ export function observeObj<T extends {}>(obj: T, onSet?: (tx: ITransaction) => v
const createAtomIfNotExists = getAtomCreator(obj);

return new Proxy(obj, {
// TODO: fix `symbol` type
defineProperty(target, p: string | number, attributes) {
const { value } = attributes;
createAtomIfNotExists(p, value);

return Reflect.defineProperty(target, p, attributes);
},
// TODO: fix `symbol` type
get(target, p: string | number, receiver) {
const atom = createAtomIfNotExists(p);
Expand All @@ -43,6 +37,13 @@ export function observeObj<T extends {}>(obj: T, onSet?: (tx: ITransaction) => v

return mutate(atom, () => Reflect.set(target, p, value, receiver), onSet);
},
// TODO: fix `symbol` type
defineProperty(target, p: string | number, attributes) {
const { value } = attributes;
createAtomIfNotExists(p, value);

return Reflect.defineProperty(target, p, attributes);
},
});
}
const arrayMethodKeys = Reflect.ownKeys(Array.prototype);
Expand All @@ -54,13 +55,6 @@ export function observeArray<T extends unknown[]>(arr: T, onSet?: (tx: ITransact
const createAtomIfNotExists = getAtomCreator(arr);

return new Proxy(arr, {
// TODO: fix `symbol` type
defineProperty(target, p: string | number, attributes) {
const { value } = attributes;
createAtomIfNotExists(p, value);

return Reflect.defineProperty(target, p, attributes);
},
// TODO: fix `symbol` type
get(target, p: string | number, receiver) {
const atom = createAtomIfNotExists(p);
Expand All @@ -73,10 +67,17 @@ export function observeArray<T extends unknown[]>(arr: T, onSet?: (tx: ITransact

return mutate(atom, () => Reflect.set(target, p, value, receiver), onSet);
},
// TODO: fix `symbol` type
defineProperty(target, p: string | number, attributes) {
const { value } = attributes;
createAtomIfNotExists(p, value);

return Reflect.defineProperty(target, p, attributes);
},
});
}

export function observe<T>(obj: T, onSet?: (tx: ITransaction) => void): any {
export function observe<T>(obj: T, onSet?: (tx: ITransaction) => void): T {
switch (typeof obj) {
case 'object':
if (obj === null) return obj;
Expand Down

0 comments on commit 49ce52f

Please sign in to comment.