Skip to content

Commit

Permalink
make exportable
Browse files Browse the repository at this point in the history
  • Loading branch information
dxu committed Nov 26, 2022
1 parent a7fee21 commit facc265
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
24 changes: 12 additions & 12 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"index.js": {
"bundled": 982,
"minified": 590,
"gzipped": 284,
"bundled": 4095,
"minified": 1253,
"gzipped": 586,
"treeshaked": {
"rollup": {
"code": 13,
"import_statements": 13
"code": 1108,
"import_statements": 57
},
"webpack": {
"code": 997
"code": 2107
}
}
},
"index.cjs.js": {
"bundled": 1392,
"minified": 771,
"gzipped": 356
"bundled": 4402,
"minified": 1424,
"gzipped": 628
},
"index.iife.js": {
"bundled": 1530,
"minified": 753,
"gzipped": 348
"bundled": 4752,
"minified": 1329,
"gzipped": 602
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
"dependencies": {},
"peerDependencies": {
"rxjs": "^7.5.7"
}
},
"exports": "./index.js"
}
18 changes: 15 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function createESMConfig(input, output) {
output: { file: output, format: "esm" },
external,
plugins: [
typescript(),
typescript({
declaration: true,
emitDeclarationOnly: true,
outDir: output,
}),
babel(getBabelOptions({ node: 8 })),
sizeSnapshot(),
resolve({ extensions }),
Expand All @@ -35,7 +39,11 @@ function createCommonJSConfig(input, output) {
output: { file: output, format: "cjs", exports: "named" },
external,
plugins: [
typescript(),
typescript({
declaration: true,
emitDeclarationOnly: true,
outDir: output,
}),
babel(getBabelOptions({ ie: 11 })),
sizeSnapshot(),
resolve({ extensions }),
Expand All @@ -57,7 +65,11 @@ function createIIFEConfig(input, output, globalName) {
},
external,
plugins: [
typescript(),
typescript({
declaration: true,
emitDeclarationOnly: true,
outDir: output,
}),
babel(getBabelOptions({ ie: 11 })),
sizeSnapshot(),
resolve({ extensions }),
Expand Down
2 changes: 1 addition & 1 deletion src/Atom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BehaviorSubject, isObservable, Observable, Subscription } from "rxjs";

export default class Atom<T> {
export class Atom<T> {
_behavior$: BehaviorSubject<T>;

_parent?: BehaviorSubject<T>[];
Expand Down
7 changes: 3 additions & 4 deletions src/Compound.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BehaviorSubject } from "rxjs";
import Atom from "./Atom";
import { Atom } from "./Atom";
import { IsntObject, KeyOfType } from "./types";

// type Tree<T extends InType> = {
Expand All @@ -15,7 +15,7 @@ function existsInObject(
return k in obj;
}

export class _Compound<T extends InType> {
class _Compound<T extends InType> {
// _atoms: {
// [key in keyof T as T[key] extends object ? never : key]: Atom<T[key]>;
// } = {};
Expand Down Expand Up @@ -96,7 +96,7 @@ type Compound<T extends InType> = _Compound<T> & {
: Atom<T[k]>;
};

const Compound: new <T extends InType>(data: T) => Compound<T> =
export const Compound: new <T extends InType>(data: T) => Compound<T> =
_Compound as any;

// export class Compound<T> implements T {
Expand Down Expand Up @@ -134,4 +134,3 @@ console.log(a2);
// e.c.get("c1");

// comp.push("a", 11);
export default Compound;
2 changes: 1 addition & 1 deletion tests/atom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Atom from "../src/Atom";
import { Atom } from "../src/Atom";

test("Simple atom values test", () => {
const atom = new Atom("aweofij");
Expand Down
4 changes: 2 additions & 2 deletions tests/compound.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Compound, { _Compound } from "../src/Compound";
import Atom from "../src/Atom";
import { Compound } from "../src/Compound";
import { Atom } from "../src/Atom";

test("Mixed object test", () => {
const comp = new Compound({ a: 100, b: 102, c: { c1: 104 }, d: () => 4 });
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"declarationDir": ".",
"declarationMap": true,
"target": "esnext",
"strict": true,
"jsx": "react-jsx",
Expand All @@ -14,6 +18,6 @@
"chemical-rx/*": ["./src/*.ts"]
}
},
"include": ["src/**/*", "tests/**/*"],
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}

0 comments on commit facc265

Please sign in to comment.