feat(vue-app): rename transition to pageTransition and deprecate it (#5558)

This commit is contained in:
Sébastien Chopin 2019-04-20 12:01:59 +02:00 committed by Pooya Parsa
parent 8b45da09b3
commit 01acf66c67
15 changed files with 67 additions and 53 deletions

View File

@ -1,7 +1,6 @@
{ {
"name": "example-routes-transitions", "name": "example-routes-transitions",
"dependencies": { "dependencies": {
"axios": "^0.15.3",
"nuxt": "latest" "nuxt": "latest"
}, },
"scripts": { "scripts": {

View File

@ -28,8 +28,6 @@
</template> </template>
<script> <script>
import axios from 'axios'
export default { export default {
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.) // Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
watchQuery: ['page'], watchQuery: ['page'],
@ -42,7 +40,8 @@ export default {
}, },
async asyncData({ query }) { async asyncData({ query }) {
const page = +query.page || 1 const page = +query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`) const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
return { return {
page: +data.page, page: +data.page,
totalPages: data.total_pages, totalPages: data.total_pages,

View File

@ -37,7 +37,7 @@ export default class TemplateContext {
typeof options.loading === 'string' typeof options.loading === 'string'
? builder.relativeToBuild(options.srcDir, options.loading) ? builder.relativeToBuild(options.srcDir, options.loading)
: options.loading, : options.loading,
transition: options.transition, pageTransition: options.pageTransition,
layoutTransition: options.layoutTransition, layoutTransition: options.layoutTransition,
dir: options.dir, dir: options.dir,
components: { components: {

View File

@ -71,19 +71,22 @@ TemplateContext {
"test": "test message", "test": "test message",
}, },
"mode": "test mode", "mode": "test mode",
"pageTransition": Object {
"name": "test_trans",
},
"router": Object { "router": Object {
"route": "test", "route": "test",
}, },
"srcDir": "test_src_dir", "srcDir": "test_src_dir",
"store": "test_store", "store": "test_store",
"test": "test_test", "test": "test_test",
"transition": Object {
"name": "test_trans",
},
"vue": Object { "vue": Object {
"config": "test_config", "config": "test_config",
}, },
}, },
"pageTransition": Object {
"name": "test_trans",
},
"plugins": Array [ "plugins": Array [
"plugins", "plugins",
], ],
@ -94,9 +97,6 @@ TemplateContext {
"testSC": true, "testSC": true,
}, },
"store": "test_store", "store": "test_store",
"transition": Object {
"name": "test_trans",
},
"uniqBy": [Function], "uniqBy": [Function],
"vue": Object { "vue": Object {
"config": "test_config", "config": "test_config",

View File

@ -37,7 +37,7 @@ describe('builder: buildContext', () => {
}, },
srcDir: 'test_src_dir', srcDir: 'test_src_dir',
loading: 'test-loading', loading: 'test-loading',
transition: { name: 'test_trans' }, pageTransition: { name: 'test_trans' },
layoutTransition: { name: 'test_layout_trans' }, layoutTransition: { name: 'test_layout_trans' },
dir: ['test_dir'], dir: ['test_dir'],
ErrorPage: 'test_error_page' ErrorPage: 'test_error_page'

View File

@ -42,7 +42,7 @@ export default () => ({
loadingIndicator: 'default', loadingIndicator: 'default',
transition: { pageTransition: {
name: 'page', name: 'page',
mode: 'out-in', mode: 'out-in',
appear: false, appear: false,

View File

@ -35,8 +35,16 @@ export function getNuxtConfig(_options) {
options._routerBaseSpecified = true options._routerBaseSpecified = true
} }
if (typeof options.transition === 'string') { // TODO: Remove for Nuxt 3
options.transition = { name: options.transition } // transition -> pageTransition
if (typeof options.transition !== 'undefined') {
consola.warn('`transition` property is deprecated in favor of `pageTransition` and will be removed in Nuxt 3')
options.pageTransition = options.transition
delete options.transition
}
if (typeof options.pageTransition === 'string') {
options.pageTransition = { name: options.pageTransition }
} }
if (typeof options.layoutTransition === 'string') { if (typeof options.layoutTransition === 'string') {
@ -275,8 +283,8 @@ export function getNuxtConfig(_options) {
defaultsDeep(options, modePreset || options.modes.universal) defaultsDeep(options, modePreset || options.modes.universal)
// If no server-side rendering, add appear true transition // If no server-side rendering, add appear true transition
if (options.render.ssr === false && options.transition) { if (options.render.ssr === false && options.pageTransition) {
options.transition.appear = true options.pageTransition.appear = true
} }
// We assume the SPA fallback path is 404.html (for GitHub Pages, Surge, etc.) // We assume the SPA fallback path is 404.html (for GitHub Pages, Surge, etc.)

View File

@ -256,6 +256,14 @@ Object {
"/var/nuxt/node_modules", "/var/nuxt/node_modules",
"/var/nuxt/test/node_modules", "/var/nuxt/test/node_modules",
], ],
"pageTransition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"plugins": Array [], "plugins": Array [],
"render": Object { "render": Object {
"bundleRenderer": Object { "bundleRenderer": Object {
@ -332,14 +340,6 @@ Object {
"less", "less",
], ],
"test": true, "test": true,
"transition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"vue": Object { "vue": Object {
"config": Object { "config": Object {
"performance": false, "performance": false,

View File

@ -230,6 +230,14 @@ Object {
"modulesDir": Array [ "modulesDir": Array [
"node_modules", "node_modules",
], ],
"pageTransition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"plugins": Array [], "plugins": Array [],
"render": Object { "render": Object {
"bundleRenderer": Object { "bundleRenderer": Object {
@ -305,14 +313,6 @@ Object {
"less", "less",
], ],
"test": true, "test": true,
"transition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"vue": Object { "vue": Object {
"config": Object { "config": Object {
"performance": undefined, "performance": undefined,
@ -562,6 +562,14 @@ Object {
"modulesDir": Array [ "modulesDir": Array [
"node_modules", "node_modules",
], ],
"pageTransition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"plugins": Array [], "plugins": Array [],
"render": Object { "render": Object {
"bundleRenderer": Object { "bundleRenderer": Object {
@ -637,14 +645,6 @@ Object {
"less", "less",
], ],
"test": true, "test": true,
"transition": Object {
"appear": false,
"appearActiveClass": "appear-active",
"appearClass": "appear",
"appearToClass": "appear-to",
"mode": "out-in",
"name": "page",
},
"vue": Object { "vue": Object {
"config": Object { "config": Object {
"performance": undefined, "performance": undefined,

View File

@ -53,12 +53,20 @@ describe('config: options', () => {
}) })
}) })
test('should transform transition/layoutTransition to name', () => { test('[Compatibility] should transform transition to pageTransition', () => {
const { transition, layoutTransition } = getNuxtConfig({ const { pageTransition, transition } = getNuxtConfig({
transition: 'test-tran', transition: 'test-tran'
})
expect(pageTransition).toMatchObject({ name: 'test-tran' })
expect(transition).toBeUndefined()
})
test('should transform pageTransition/layoutTransition to name', () => {
const { pageTransition, layoutTransition } = getNuxtConfig({
pageTransition: 'test-tran',
layoutTransition: 'test-layout-tran' layoutTransition: 'test-layout-tran'
}) })
expect(transition).toMatchObject({ name: 'test-tran' }) expect(pageTransition).toMatchObject({ name: 'test-tran' })
expect(layoutTransition).toMatchObject({ name: 'test-layout-tran' }) expect(layoutTransition).toMatchObject({ name: 'test-layout-tran' })
}) })
@ -96,9 +104,9 @@ describe('config: options', () => {
expect(render.ssr).toEqual(true) expect(render.ssr).toEqual(true)
}) })
test('should add appear true in transition when no ssr', () => { test('should add appear true in pageTransition when no ssr', () => {
const { transition } = getNuxtConfig({ render: { ssr: false } }) const { pageTransition } = getNuxtConfig({ render: { ssr: false } })
expect(transition.appear).toEqual(true) expect(pageTransition.appear).toEqual(true)
}) })
test('should return 404.html as default generate.fallback', () => { test('should return 404.html as default generate.fallback', () => {

View File

@ -36,7 +36,7 @@ Vue.use(Meta, {
}) })
const defaultTransition = <%= const defaultTransition = <%=
serialize(transition) serialize(pageTransition)
.replace('beforeEnter(', 'function(').replace('enter(', 'function(').replace('afterEnter(', 'function(') .replace('beforeEnter(', 'function(').replace('enter(', 'function(').replace('afterEnter(', 'function(')
.replace('enterCancelled(', 'function(').replace('beforeLeave(', 'function(').replace('leave(', 'function(') .replace('enterCancelled(', 'function(').replace('beforeLeave(', 'function(').replace('leave(', 'function(')
.replace('afterLeave(', 'function(').replace('leaveCancelled(', 'function(').replace('beforeAppear(', 'function(') .replace('afterLeave(', 'function(').replace('leaveCancelled(', 'function(').replace('beforeAppear(', 'function(')

View File

@ -63,7 +63,7 @@ export default {
bad: null, bad: null,
'': true '': true
}, },
transition: false, pageTransition: false,
plugins: [ plugins: [
'~/plugins/vuex-module', '~/plugins/vuex-module',
'~/plugins/dir-plugin', '~/plugins/dir-plugin',

View File

@ -2,7 +2,7 @@ import path from 'path'
export default { export default {
modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'), modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'),
transition: false, pageTransition: false,
vue: { vue: {
config: { config: {
silent: false, silent: false,

View File

@ -1,6 +1,6 @@
export default { export default {
mode: 'spa', mode: 'spa',
transition: false, pageTransition: false,
render: { render: {
http2: { http2: {
push: true push: true

View File

@ -34,7 +34,7 @@ export default {
} }
}, },
modulesDir: [path.join(__dirname, '..', '..', '..', 'node_modules')], modulesDir: [path.join(__dirname, '..', '..', '..', 'node_modules')],
transition: 'test', pageTransition: 'test',
layoutTransition: 'test', layoutTransition: 'test',
loadingIndicator: 'circle', loadingIndicator: 'circle',
extensions: 'ts', extensions: 'ts',