Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Nov 21, 2024
1 parent 9ba959b commit 597ae8d
Show file tree
Hide file tree
Showing 9 changed files with 2,817 additions and 2,815 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.2",
"version": "1.2.0",
"name": "organism-react-scroll-nav",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,6 +34,7 @@
"reshow-app": "*"
},
"exports": {
"types": "./types/index.d.ts",
"require": "./build/cjs/src/index.js",
"import": "./build/es/src/index.mjs"
},
Expand Down
6 changes: 3 additions & 3 deletions src/stores/scrollStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Scroller {

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

triggerScroll(scrollNode) {
const scrollId = get(scrollNode, ["id"]) || DEFAULT_SCROLL_ID;
Expand Down Expand Up @@ -137,7 +137,7 @@ class Scroller {
}

getOffset(id) {
const offset = this.store.getMap("offsetCache")[id];
const offset = get(this.store.getMap("offsetCache"), [id]);
if (offset && offset.h && offset.w) {
return offset;
} else {
Expand Down Expand Up @@ -295,7 +295,7 @@ const [store, delayScrollDispatch] = ImmutableStore(
const scrollStore = {
...store,
scroller: oDelayScroller,
};
};

oDelayScroller.dispatch = delayScrollDispatch;
oDelayScroller.store = store;
Expand Down
3 changes: 3 additions & 0 deletions src/ui/organisms/ScrollInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-check

import ScrollSpy from "../organisms/ScrollSpy";
import ScrollReceiver from "../organisms/ScrollReceiver";
import * as React from "react";

const ScrollInfo = ({ children, ...others }) => (
<ScrollSpy {...others}>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/organisms/ScrollReceiver.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useScrollReceiver = (props) => {
} = props;

/** @type {React.MutableRefObject<boolean>} */
const lastIsShown = useRef();
const lastIsShown = useRef(false);
const store = noDelay ? fastScrollStore : scrollStore;
const { scroll: scrollInfo = {} } = useReturn(["scroll"], store);
const activeId = store.getState().get("m" + scrollMargin);
Expand Down
19 changes: 14 additions & 5 deletions src/ui/organisms/__tests__/ScrollReceiverTest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { expect } from "chai";
import { render } from "reshow-unit";
import { render, sleep, act, waitFor } from "reshow-unit";

import ScrollReceiver from "../ScrollReceiver";
import ScrollSpy from "../ScrollSpy";

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

it("test simple ScrollReceiver", () => {
const vDom = <ScrollReceiver container={TestEl} />;
const uFake = render(vDom);
expect(uFake.html()).to.be.equal("<div></div>");
it("test simple ScrollReceiver", async () => {
const vDom = (
<ScrollSpy>
<ScrollReceiver container={TestEl} />
</ScrollSpy>
);
let wrap = render(vDom);
act(undefined, 500);
await sleep(() => {}, 350);
await waitFor(() => {
expect(wrap.html()).to.have.string("<div></div>");
});
});
});
8 changes: 4 additions & 4 deletions types/stores/fastScrollStore.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default scrollStore;
declare const scrollStore: {
scroller: FastScroller;
reset: () => any;
getState: () => any;
addListener: import("reshow-flux-base/types/type").EmitterAddCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
getMap: (arg0: import("reshow-flux/types/ImmutableStore").MapKeyType) => any;
reset: () => import("reshow-flux/types/ImmutableStore").StateMap;
getState: () => import("reshow-flux/types/ImmutableStore").StateMap;
addListener: import("reshow-flux-base/types/type").EmitterAddCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
};
declare class FastScroller extends Scroller {
}
Expand Down
10 changes: 5 additions & 5 deletions types/stores/scrollStore.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default scrollStore;
declare const scrollStore: {
scroller: Scroller;
reset: () => any;
getState: () => any;
addListener: import("reshow-flux-base/types/type").EmitterAddCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<any, import("reshow-flux/types/ImmutableStore").MaybeMapType>;
getMap: (arg0: import("reshow-flux/types/ImmutableStore").MapKeyType) => any;
reset: () => import("reshow-flux/types/ImmutableStore").StateMap;
getState: () => import("reshow-flux/types/ImmutableStore").StateMap;
addListener: import("reshow-flux-base/types/type").EmitterAddCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
removeListener: import("reshow-flux-base/types/type").EmitterRemoveCall<import("reshow-flux/types/ImmutableStore").StateMap, import("reshow-flux/types/ImmutableStore").ImmutableAction>;
};
export class Scroller {
storeName: string;
Expand Down Expand Up @@ -36,7 +36,7 @@ export class Scroller {
getInitialState(): Map<string, number>;
trigger: any;
scrollMonitor: any;
scrollDebounce: (option: any) => void;
scrollDebounce: import("call-func/types/debounce").DebounceExecutor;
bindHandleResize: any;
reduce(state: any, action: any): any;
}
Expand Down
2 changes: 1 addition & 1 deletion types/ui/organisms/ScrollReceiver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export type ScrollReceiverProps = object;
*/
declare function ScrollReceiver(props: ScrollReceiverProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
declare namespace ScrollReceiver {
const displayName: string;
let displayName: string;
}
Loading

0 comments on commit 597ae8d

Please sign in to comment.