Skip to content

Commit 597ae8d

Browse files
committed
improve types
1 parent 9ba959b commit 597ae8d

File tree

9 files changed

+2817
-2815
lines changed

9 files changed

+2817
-2815
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1.2",
2+
"version": "1.2.0",
33
"name": "organism-react-scroll-nav",
44
"repository": {
55
"type": "git",
@@ -34,6 +34,7 @@
3434
"reshow-app": "*"
3535
},
3636
"exports": {
37+
"types": "./types/index.d.ts",
3738
"require": "./build/cjs/src/index.js",
3839
"import": "./build/es/src/index.mjs"
3940
},

src/stores/scrollStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Scroller {
8080

8181
checkIsActive = (scrollTop, pos) => {
8282
return scrollTop >= pos.top - 1 && scrollTop <= pos.bottom - 2;
83-
}
83+
};
8484

8585
triggerScroll(scrollNode) {
8686
const scrollId = get(scrollNode, ["id"]) || DEFAULT_SCROLL_ID;
@@ -137,7 +137,7 @@ class Scroller {
137137
}
138138

139139
getOffset(id) {
140-
const offset = this.store.getMap("offsetCache")[id];
140+
const offset = get(this.store.getMap("offsetCache"), [id]);
141141
if (offset && offset.h && offset.w) {
142142
return offset;
143143
} else {
@@ -295,7 +295,7 @@ const [store, delayScrollDispatch] = ImmutableStore(
295295
const scrollStore = {
296296
...store,
297297
scroller: oDelayScroller,
298-
};
298+
};
299299

300300
oDelayScroller.dispatch = delayScrollDispatch;
301301
oDelayScroller.store = store;

src/ui/organisms/ScrollInfo.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// @ts-check
2+
13
import ScrollSpy from "../organisms/ScrollSpy";
24
import ScrollReceiver from "../organisms/ScrollReceiver";
5+
import * as React from "react";
36

47
const ScrollInfo = ({ children, ...others }) => (
58
<ScrollSpy {...others}>

src/ui/organisms/ScrollReceiver.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const useScrollReceiver = (props) => {
2626
} = props;
2727

2828
/** @type {React.MutableRefObject<boolean>} */
29-
const lastIsShown = useRef();
29+
const lastIsShown = useRef(false);
3030
const store = noDelay ? fastScrollStore : scrollStore;
3131
const { scroll: scrollInfo = {} } = useReturn(["scroll"], store);
3232
const activeId = store.getState().get("m" + scrollMargin);
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { expect } from "chai";
2-
import { render } from "reshow-unit";
2+
import { render, sleep, act, waitFor } from "reshow-unit";
33

44
import ScrollReceiver from "../ScrollReceiver";
5+
import ScrollSpy from "../ScrollSpy";
56

67
describe("Test ScrollReceiver", () => {
78
const TestEl = () => <div />;
89

9-
it("test simple ScrollReceiver", () => {
10-
const vDom = <ScrollReceiver container={TestEl} />;
11-
const uFake = render(vDom);
12-
expect(uFake.html()).to.be.equal("<div></div>");
10+
it("test simple ScrollReceiver", async () => {
11+
const vDom = (
12+
<ScrollSpy>
13+
<ScrollReceiver container={TestEl} />
14+
</ScrollSpy>
15+
);
16+
let wrap = render(vDom);
17+
act(undefined, 500);
18+
await sleep(() => {}, 350);
19+
await waitFor(() => {
20+
expect(wrap.html()).to.have.string("<div></div>");
21+
});
1322
});
1423
});

types/stores/fastScrollStore.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export default scrollStore;
22
declare const scrollStore: {
33
scroller: FastScroller;
4+
reset: () => any;
5+
getState: () => any;
6+
addListener: import("reshow-flux-base/types/type").EmitterAddCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
7+
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
48
getMap: (arg0: import("reshow-flux/types/ImmutableStore").MapKeyType) => any;
5-
reset: () => import("reshow-flux/types/ImmutableStore").StateMap;
6-
getState: () => import("reshow-flux/types/ImmutableStore").StateMap;
7-
addListener: import("reshow-flux-base/types/type").EmitterAddCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
8-
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
99
};
1010
declare class FastScroller extends Scroller {
1111
}

types/stores/scrollStore.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export default scrollStore;
22
declare const scrollStore: {
33
scroller: Scroller;
4+
reset: () => any;
5+
getState: () => any;
6+
addListener: import("reshow-flux-base/types/type").EmitterAddCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
7+
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
48
getMap: (arg0: import("reshow-flux/types/ImmutableStore").MapKeyType) => any;
5-
reset: () => import("reshow-flux/types/ImmutableStore").StateMap;
6-
getState: () => import("reshow-flux/types/ImmutableStore").StateMap;
7-
addListener: import("reshow-flux-base/types/type").EmitterAddCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
8-
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
99
};
1010
export class Scroller {
1111
storeName: string;
@@ -36,7 +36,7 @@ export class Scroller {
3636
getInitialState(): Map<string, number>;
3737
trigger: any;
3838
scrollMonitor: any;
39-
scrollDebounce: (option: any) => void;
39+
scrollDebounce: import("call-func/types/debounce").DebounceExecutor;
4040
bindHandleResize: any;
4141
reduce(state: any, action: any): any;
4242
}

types/ui/organisms/ScrollReceiver.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export type ScrollReceiverProps = object;
55
*/
66
declare function ScrollReceiver(props: ScrollReceiverProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
77
declare namespace ScrollReceiver {
8-
const displayName: string;
8+
let displayName: string;
99
}

0 commit comments

Comments
 (0)