history#History TypeScript Examples

The following examples show how to use history#History. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts    From NetStatus with MIT License 7 votes vote down vote up
function historyMatchesLocation(history: History, path: string): boolean {
    let location = history.location.pathname;

    if ( location === path ) { return true; }

    if ( location[0] === '/' ) {
        location = history.location.pathname.substring(1); /* remove leading / */
    }

    const matched = path === location;

    return matched;
}
Example #2
Source File: filters.tsx    From ke with MIT License 6 votes vote down vote up
setFilterValue = (
  location: Location,
  filterName: string,
  filterValue: Accessor<string>,
  history: History,
  setPage?: (page: number) => void
): void => {
  const filters = FilterManager.getFilters(location.search)
  filters.push({ filterName, filterOperation: undefined, value: filterValue })
  FilterManager.resetPagination(setPage)
  FilterManager.setFilters(location, filters, history)
}
Example #3
Source File: store.ts    From lightning-terminal with MIT License 6 votes vote down vote up
constructor(
    lnd: LndApi,
    loop: LoopApi,
    pool: PoolApi,
    lit: LitApi,
    storage: AppStorage,
    history: History,
    csv: CsvExporter,
    log: Logger,
  ) {
    makeAutoObservable(this, {}, { deep: false, autoBind: true });

    this.api = { lnd, loop, pool, lit };
    this.storage = storage;
    this.router = new RouterStore(history);
    this.csv = csv;
    this.log = log;
  }
Example #4
Source File: WebApplicationNavigatorProvider.tsx    From legend-studio with Apache License 2.0 6 votes vote down vote up
WebApplicationNavigatorProvider: React.FC<{
  children: React.ReactNode;
}> = ({ children }) => {
  const history = useHistory() as History;
  const navigator = useLocalObservable(
    () => new WebApplicationNavigator(history),
  );
  return (
    <WebApplicationNavigatorContext.Provider value={navigator}>
      {children}
    </WebApplicationNavigatorContext.Provider>
  );
}
Example #5
Source File: routerStore.ts    From lightning-terminal with MIT License 6 votes vote down vote up
constructor(history: History) {
    makeAutoObservable(this, { history: false }, { deep: false, autoBind: true });

    this.history = history;
    this.location = history.location;

    history.listen(({ location }) => {
      runInAction(() => {
        this.location = location;
      });
    });
  }
Example #6
Source File: store.ts    From mysterium-vpn-desktop with MIT License 6 votes vote down vote up
constructor(root: RootStore, history: History) {
        makeObservable(this, {
            location: computed,
            showLoading: action,
            goHome: action,
            navigateToInitialRoute: action,
            navigateOnConnectionStatus: action,
            openChat: action,
        })
        this.root = root
        this.history = history
    }
Example #7
Source File: index.tsx    From react-micro-frontends with MIT License 6 votes vote down vote up
// render micro frontend function
(window as any).renderFoo = (containerId: string, history: History) => {
  ReactDOM.render(
    <React.StrictMode>
      <App history={history} />
    </React.StrictMode>,
    document.getElementById(containerId),
  );
};
Example #8
Source File: DashboardPage.tsx    From anthem with Apache License 2.0 6 votes vote down vote up
getMobileDashboardNavigationLink = ({
  title,
  address,
  network,
  history,
  pathname,
  localizedTitle,
}: INavItemProps & { history: History }) => {
  const active = onActiveRoute(pathname, localizedTitle);
  const path = `/${network.name.toLowerCase()}/${title.toLowerCase()}?address=${address}`;
  const onClickFunction = () => {
    history.push(path);
    runAnalyticsForTab(title);
  };
  return (
    <MenuItem
      key={title}
      text={localizedTitle}
      onClick={onClickFunction}
      color={active ? COLORS.CHORUS : undefined}
      data-cy={`${title.toLowerCase()}-navigation-link`}
    />
  );
}
Example #9
Source File: tour.tsx    From clearflask with Apache License 2.0 6 votes vote down vote up
setStep = async (
  dispatch: ThunkDispatch<ReduxStateTour, undefined, AllTourActions>,
  history: History,
  location: Location,
  guideId: string,
  guide: TourDefinitionGuide,
  onGuideCompleted: TourData['onGuideCompleted'],
  stepId?: string,
  step?: TourDefinitionGuideStep,
) => {
  dispatch({
    type: 'tourSetStep', payload: {
      activeStep: undefined,
    }
  });
  if (!!stepId && !!step) {
    if (!!step.openPath && location.pathname !== step.openPath) {
      await new Promise(resolve => setTimeout(resolve, 250));
      history.push(step.openPath);
    }
    await new Promise(resolve => setTimeout(resolve, step.showDelay !== undefined ? step.showDelay : 250));
    dispatch({
      type: 'tourSetStep', payload: {
        activeStep: { guideId, stepId },
      }
    });
  } else {
    if (guide.onComplete?.openPath) {
      await new Promise(resolve => setTimeout(resolve, 250));
      history.push(guide.onComplete.openPath);
    }
    onGuideCompleted?.(guideId, guide);
  }
}
Example #10
Source File: configureStore.ts    From che-dashboard-next with Eclipse Public License 2.0 6 votes vote down vote up
export default function configureStore(history: History, initialState?: AppState): Store {
  const middleware = [
    thunk,
    routerMiddleware(history)
  ];

  const rootReducer = combineReducers({
    ...reducers,
    router: connectRouter(history)
  });

  const enhancers: any[] = [];
  const windowIfDefined = typeof window === 'undefined' ? null : window as any;
  if (windowIfDefined && windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__) {
    enhancers.push(windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__() as any);
  }

  return createStore(
    rootReducer,
    initialState,
    compose(applyMiddleware(...middleware), ...enhancers)
  );
}
Example #11
Source File: store.ts    From mysterium-vpn-desktop with MIT License 6 votes vote down vote up
constructor(history: History) {
        makeObservable(this, {
            os: observable,
            isWindows: computed,
            isMacOS: computed,
            isLinux: computed,
        })
        this.navigation = new NavigationStore(this, history)
        this.daemon = new DaemonStore(this)
        this.config = new ConfigStore(this)
        this.filters = new Filters(this)
        this.identity = new IdentityStore(this)
        this.onboarding = new OnboardingStore(this)
        this.proposals = new ProposalStore(this)
        this.connection = new ConnectionStore(this)
        this.payment = new PaymentStore(this)
        this.feedback = new FeedbackStore(this)
        this.referral = new ReferralStore(this)

        // Setup cross-store reactions after all injections.
        this.daemon.setupReactions()
        this.filters.setupReactions()
        this.identity.setupReactions()
        this.proposals.setupReactions()
        this.payment.setupReactions()
        this.connection.setupReactions()
        this.setupReactions()

        ipcRenderer.invoke(MainIpcListenChannels.GetOS).then((os) => {
            runInAction(() => {
                this.os = os
            })
        })
    }
Example #12
Source File: index.tsx    From nouns-monorepo with GNU General Public License v3.0 6 votes vote down vote up
createRootReducer = (history: History) =>
  combineReducers({
    router: connectRouter(history),
    account,
    application,
    auction,
    logs,
    pastAuctions,
    onDisplayAuction,
  })
Example #13
Source File: rootReducer.ts    From deskreen with GNU Affero General Public License v3.0 6 votes vote down vote up
// eslint-disable-next-line import/no-cycle
// import counterReducer from './features/counter/counterSlice';

export default function createRootReducer(history: History) {
  return combineReducers({
    router: connectRouter(history),
    // counter: counterReducer,
  });
}
Example #14
Source File: CommandPalette.tsx    From amplication with Apache License 2.0 6 votes vote down vote up
export function getCommands(
  data: TData,
  history: History,
  currentAppId: string | undefined
): Command[] {
  const appCommands = data.apps.flatMap((app) => {
    const isCurrentApp = currentAppId === app.id;
    const appCommands = getAppCommands(app, history, isCurrentApp);
    const entityCommands = app.entities.flatMap((entity) =>
      getEntityCommands(entity, app, history, isCurrentApp)
    );
    return [...appCommands, ...entityCommands];
  });
  const staticCommands = getStaticCommands(history);
  return [...staticCommands, ...appCommands];
}
Example #15
Source File: offline.tsx    From NetStatus with MIT License 6 votes vote down vote up
route: IRoute = {
    path: "/offline",
    isShowing: (history: History) => util.historyMatchesLocation(history, route.path),
    component: (props: any) => <Controller {...props} />,
    navigate: (history: History, props?: RouteComponentProps<{}>) => { 
        if ( route.isShowing(history) ) { return; }  
        history.push(route.path)
    }
}
Example #16
Source File: CommandPalette.tsx    From amplication with Apache License 2.0 6 votes vote down vote up
export function getEntityCommands(
  entity: EntityDescriptor,
  app: AppDescriptor,
  history: History,
  isCurrentApp: boolean
): Command[] {
  return [
    new NavigationCommand(
      history,
      entity.displayName,
      `/${app.id}/entities/${entity.id}`,
      TYPE_ENTITY,
      isCurrentApp,
      true,
      app.name,
      app.color
    ),
  ];
}
Example #17
Source File: dashboard.tsx    From NetStatus with MIT License 6 votes vote down vote up
route: IRoute = {
    path: "/dashboard",
    isShowing: (history: History) => util.historyMatchesLocation(history, route.path),
    component: (props: any) => <Controller {...props} />,
    navigate: (history: History, props?: RouteComponentProps<{}>) => { 
        if ( route.isShowing(history) ) { return; }  
        history.push(route.path) 
    }
}
Example #18
Source File: useHistory.ts    From rocon with MIT License 6 votes vote down vote up
useHistory = (): History => {
  const history = useContext(HistoryContext);
  if (history === undefined) {
    throw new Error(
      "No history found in the context. Please make sure you have placed RoconRoot above."
    );
  }
  return history.history;
}
Example #19
Source File: rootReducer.ts    From memex with MIT License 5 votes vote down vote up
export default function createRootReducer(history: History) {
  return combineReducers({
    router: connectRouter(history),
    layout: layoutReducer,
    document: documentReducer,
    note: notesReducer,
  });
}
Example #20
Source File: router.ts    From reactant with MIT License 5 votes vote down vote up
constructor(
    protected portDetector: PortDetector,
    @inject(SharedAppOptions) protected sharedAppOptions: ISharedAppOptions,
    @inject(RouterOptions) protected options: IRouterOptions
  ) {
    super({
      ...options,
      autoCreateHistory: !(
        (sharedAppOptions.type === 'SharedWorker' ||
          sharedAppOptions.type === 'ServiceWorker') &&
        sharedAppOptions.port === 'server'
      ),
    });

    this.portDetector.onServer((transport) => {
      return transport!.listen(
        syncRouterName,
        async () => this.router?.location
      );
    });
    this.portDetector.onClient((transport) => {
      transport!.emit(syncRouterName).then((location) => {
        if (!location) return;
        const action = this.onLocationChanged(location, 'REPLACE');
        this[storeKey]?.dispatch(action!);
      });
    });

    if (
      sharedAppOptions.type === 'SharedWorker' ||
      sharedAppOptions.type === 'ServiceWorker'
    ) {
      this.portDetector.onServer((transport) => {
        const history: History = {
          push: async (path: string, state?: Record<string, any>) => {
            this._router = await transport.emit(routerChangeName, {
              method: 'push',
              args: [path, state],
            });
          },
          replace: async (path: string, state?: Record<string, any>) => {
            this._router = await transport.emit(routerChangeName, {
              method: 'replace',
              args: [path, state],
            });
          },
          go: async (n: number) => {
            this._router = await transport.emit(routerChangeName, {
              method: 'go',
              args: [n],
            });
          },
          goBack: async () => {
            this._router = await transport.emit(routerChangeName, {
              method: 'goBack',
              args: [],
            });
          },
          goForward: async () => {
            this._router = await transport.emit(routerChangeName, {
              method: 'goForward',
              args: [],
            });
          },
        } as any;
        this.history = history;
      });
      this.portDetector.onClient((transport) => {
        return transport.listen(routerChangeName, ({ method, args = [] }) => {
          const fn: Function = this.history[method];
          fn(...args);
          return this.router;
        });
      });
    }
  }
Example #21
Source File: index.tsx    From rocon with MIT License 5 votes vote down vote up
renderInHistory = (history: History, element: ReactElement) => {
  return render(<RoconRoot history={history}>{element}</RoconRoot>);
}
Example #22
Source File: routerStore.ts    From lightning-terminal with MIT License 5 votes vote down vote up
/** the history object */
  history: History;
Example #23
Source File: useNavigate.ts    From rocon with MIT License 5 votes vote down vote up
cache = new WeakMap<History, Navigate>()
Example #24
Source File: store.ts    From mysterium-vpn-desktop with MIT License 5 votes vote down vote up
history: History
Example #25
Source File: _history.ts    From rocon with MIT License 5 votes vote down vote up
createMockHistory = (): History => {
  return ({
    push: jest.fn(),
  } as unknown) as History;
}
Example #26
Source File: store.ts    From mysterium-vpn-desktop with MIT License 5 votes vote down vote up
createRootStore = (history: History): RootStore => {
    rootStore = new RootStore(history)
    StoreContext = React.createContext(rootStore)
    return rootStore
}
Example #27
Source File: RedirectToCluster.tsx    From assisted-ui-lib with Apache License 2.0 5 votes vote down vote up
redirectToCluster = (history: History, id: string) => {
  history.push(`${routeBasePath}/clusters/${id}`);
}
Example #28
Source File: Tracker.ts    From nosgestesclimat-site with MIT License 5 votes vote down vote up
connectToHistory(history: History) {
		this.unlistenFromHistory = history.listen((loc) => {
			this.track(loc)
		})

		return history
	}
Example #29
Source File: WebApplicationNavigator.ts    From legend-studio with Apache License 2.0 5 votes vote down vote up
constructor(historyApiClient: History) {
    this.historyAPI = historyApiClient;
  }