Skip to content

Commit

Permalink
refactor(atom): update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 21, 2018
1 parent 4d3785f commit ea7b175
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/atom/src/atom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IEquiv, Watch, Predicate } from "@thi.ng/api/api";
import { illegalState } from "@thi.ng/api/error";
import { IWatch } from "@thi.ng/api/mixins/iwatch";
import { Path, setIn, updateIn } from "@thi.ng/paths";

Expand All @@ -20,7 +21,7 @@ export class Atom<T> implements

constructor(val?: T, valid?: Predicate<T>) {
if (valid && !valid(val)) {
throw new Error("initial state did not validate");
illegalState("initial state value did not validate");
}
this.value = val;
this.valid = valid;
Expand Down
7 changes: 4 additions & 3 deletions packages/atom/src/cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IID, IRelease, Watch } from "@thi.ng/api/api";
import { illegalArity, illegalArgs } from "@thi.ng/api/error";
import { isArray } from "@thi.ng/checks/is-array";
import { isFunction } from "@thi.ng/checks/is-function";
import { Path, getter, setter } from "@thi.ng/paths";
Expand Down Expand Up @@ -65,7 +66,7 @@ export class Cursor<T> implements
update = setter(<Path>opts.path);
}
} else {
throw new Error("missing path config");
illegalArgs("missing path config");
}
break;
case 2:
Expand All @@ -77,13 +78,13 @@ export class Cursor<T> implements
[parent, lookup, update] = args;
break;
default:
throw new Error(`illegal arity: ${args.length}`);
illegalArity(args.length);
}
this.parent = parent;
this.id = id || `cursor-${Cursor.NEXT_ID++}`;
this.selfUpdate = false;
if (!lookup || !update) {
throw new Error("illegal args");
illegalArgs();
}
this.local = new Atom<T>(lookup(parent.deref()), validate);
this.local.addWatch(this.id, (_, prev, curr) => {
Expand Down

0 comments on commit ea7b175

Please sign in to comment.