Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLの履歴管理、state管理を実装 #1

Merged
merged 6 commits into from
Aug 27, 2018
Merged

Conversation

simiraaaa
Copy link
Collaborator

@simiraaaa simiraaaa commented Aug 16, 2018

  • state は現在のページの this._history に対してのインデックス
  • this._history.length は history.length と同じ数値になることを想定している
  • canBack : 戻れるかどうかの判定
  • canForward : 進めるかどうかの判定
  • getPrev : 前のページのpathを返す。返せない場合は null
  • getNext : 次のページのpathを返す。返せない場合は null
  • popState : onpopstate でURLとstateが更新されたときに、routefulの状態も更新する
  • state が想定外の場合は、 isLegacy フラグを立てて、今回実装した機能の処理をしないようにする
  • 最初にアクセスしたページはstateがnullになるので、replaceState で最適な数値に変更している
  • popstate で戻った場合はisBack、進んだ場合は isForward

想定されるバグ

別のサイトからこの機能を実装したページへブラウザバックを使用して遷移した際に、stateがnullの場合、戻れなくても canBack がtrueになる可能性がある (理論上起こることはあるが再現したことはない)

@snuffy
Copy link

snuffy commented Aug 21, 2018

@simiraaaa 動作確認 LGTM

@phi-jp
Copy link
Owner

phi-jp commented Aug 27, 2018

@simiraaaa 圧倒的にコメントがないから追加してくれい

@simiraaaa
Copy link
Collaborator Author

@phi-jp 追加しました

@phi-jp
Copy link
Owner

phi-jp commented Aug 27, 2018

@simiraaaa 良いね
LGTM

@phi-jp phi-jp merged commit 47863fe into develop Aug 27, 2018
@phi-jp phi-jp deleted the feature/history-state branch August 27, 2018 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants