-
-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(history): Remove event listeners when all apps are destroyed. #3172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
037a643
feat(history): Remove event listeners when all apps are destroyed.
f923d37
fix(tests): Adding test assertions
6fdde38
fix(feedback): addressing @posva's feedback
db3e347
fix(index): posva's feedback
9d0ba02
feat(tests): adding multi-app test
97470df
fix(feedback): posva's feedback
1c90043
fix(feedback): unmounting apps with buttons outside of the app
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
<button id="unmount">Unmount</button> | ||
<hr /> | ||
<div id="app"></div> | ||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/basic.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
<button id="unmount">Unmount</button> | ||
<hr /> | ||
<div id="app"></div> | ||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/hash-mode.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
|
||
// track number of popstate listeners | ||
let numPopstateListeners = 0 | ||
const listenerCountDiv = document.getElementById('popcount') | ||
listenerCountDiv.textContent = 0 | ||
|
||
const originalAddEventListener = window.addEventListener | ||
const originalRemoveEventListener = window.removeEventListener | ||
window.addEventListener = function (name, handler) { | ||
if (name === 'popstate') { | ||
listenerCountDiv.textContent = | ||
++numPopstateListeners | ||
} | ||
return originalAddEventListener.apply(this, arguments) | ||
} | ||
window.removeEventListener = function (name, handler) { | ||
if (name === 'popstate') { | ||
listenerCountDiv.textContent = | ||
--numPopstateListeners | ||
} | ||
return originalRemoveEventListener.apply(this, arguments) | ||
} | ||
|
||
// 1. Use plugin. | ||
// This installs <router-view> and <router-link>, | ||
// and injects $router and $route to all router-enabled child components | ||
Vue.use(VueRouter) | ||
|
||
const looper = [1, 2, 3] | ||
|
||
looper.forEach((n) => { | ||
let vueInstance | ||
const mountEl = document.getElementById('mount' + n) | ||
const unmountEl = document.getElementById('unmount' + n) | ||
|
||
mountEl.addEventListener('click', () => { | ||
// 2. Define route components | ||
const Home = { template: '<div>home</div>' } | ||
const Foo = { template: '<div>foo</div>' } | ||
|
||
// 3. Create the router | ||
const router = new VueRouter({ | ||
mode: 'history', | ||
base: __dirname, | ||
routes: [ | ||
{ path: '/', component: Home }, | ||
{ path: '/foo', component: Foo } | ||
] | ||
}) | ||
|
||
// 4. Create and mount root instance. | ||
// Make sure to inject the router. | ||
// Route components will be rendered inside <router-view>. | ||
vueInstance = new Vue({ | ||
router, | ||
template: ` | ||
<div id="app-${n}"> | ||
<h1>Basic</h1> | ||
<ul> | ||
<li><router-link to="/">/</router-link></li> | ||
<li><router-link to="/foo">/foo</router-link></li> | ||
</ul> | ||
<router-view class="view"></router-view> | ||
</div> | ||
` | ||
}).$mount('#app-' + n) | ||
}) | ||
|
||
unmountEl.addEventListener('click', () => { | ||
vueInstance.$destroy() | ||
vueInstance.$el.innerHTML = '' | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
|
||
<button id="mount1">Mount App 1</button> | ||
<button id="mount2">Mount App 2</button> | ||
<button id="mount3">Mount App 3</button> | ||
|
||
<hr /> | ||
|
||
<button id="unmount1">Unmount App 1</button> | ||
<button id="unmount2">Unmount App 2</button> | ||
<button id="unmount3">Unmount App 3</button> | ||
|
||
<hr /> | ||
|
||
popstate count: <span id="popcount"></span> | ||
|
||
<div id="app-1"></div> | ||
<div id="app-2"></div> | ||
<div id="app-3"></div> | ||
|
||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/multi-app.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.