question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would it be possible to allow a custom history object to be passed as a prop to SearchkitManager? I think this would be useful allow integration with things like react-router-redux.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ssetemcommented, Jun 14, 2017

yep @abousamra we upgraded and added hook to provide own history in v2.1

Thanks, I will close this issue down now

1reaction
SickSAMAcommented, Jul 1, 2016

Allowing custom history object is not simple, a lot of scenarios need to be considered.

Suppose we have page A, B(Searchkit), C. They are in a single page app.

  1. If a history is created in A, and user use a link navigate to B. Then searchkit’s listener is not triggered because the location.action is PUSH. Only when a history’s first generated location or browser’s popstate event generated location has a POP state.
  2. Normally when navigating from B to C, B will unmount. However, if C is a popup which is quite common (Instagram, Behance), So from B to C it can be a PUSH or POP(use browser’s forward button). If it’s a POP, then the listener is triggered a new search is done, which shouldn’t happen.

To solve above issues, I propose that search is triggered and only triggered by history’s event and providing a pauseListenHistory and resumeListenHistory to disable the listener if on other pages.

setupListeners() {
  this.initialLoading = true
  if(this.options.useHistory) {
    this.unlistenHistory()
    this.history = this.options.history || createHistory()
    this.historyFreezed = false; // indicate whether history is paused for listening
    this.listenToHistory()
  } else {
    this.runInitialSearch()
  }
}

listenToHistory(){
  let callsBeforeListen = (this.options.searchOnLoad) ? 1: 2
  this._unlistenHistory = this.history.listen(after(callsBeforeListen,(location)=>{
    if(!this.historyFreezed) { // only triggered when not freezed
      this.registrationCompleted.then(()=>{
        this.searchFromUrlQuery(location.query)
      }).catch((e)=> {
        console.error(e.stack)
      })
    }
  }))
}

performSearch(replaceState=false, notifyState=true){
  if(notifyState && !isEqual(this.accessors.getState(), this.state)){
    this.accessors.notifyStateChange(this.state)
  }
  this.state = this.accessors.getState(); // moved from _search to here
  if(this.options.useHistory){
    const historyMethod = (replaceState) ?
      this.history.replace : this.history.push
    historyMethod({pathname: window.location.pathname, query:this.state})
  }
  else {
    this._search()
  }
}

pauseListenHistory(){
  if (this.historyFreezed !== undefined) 
    this.historyFreezed = true
}

resumeListenHistory(){
  if (this.historyFreezed !== undefined) 
    this.historyFreezed = false
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The history of customs from the beginning to the present
Customs already existed in the third millennium before Christ in the ancient advanced civilizations of ancient Egypt and the Orient.
Read more >
History of the U.S. Customs Service
Only a few days after Customs drew its first breath, on August 5, 1789, the power of the service went from legal theory...
Read more >
A Brief History of Customs | Border Bee
Evidence of Customs activity has been excavated all over the world, from the ports of Ancient Greece to the Great Wall of China....
Read more >
History - National U.S. Customs Museum Foundation
The US Customs Service was created to provide revenue to the new nation through the collection of duties and tariffs on imported goods....
Read more >
Customs - Wikipedia
Customs is an authority or agency in a country responsible for collecting tariffs and for controlling the flow of goods, including animals, transports, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found