Skip to content

Commit

Permalink
[chore] Rename initialValue property to initialValues
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 24, 2019
1 parent edd6f63 commit 10c35c1
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/@sanity/base/test/mocks/schema.js
Expand Up @@ -8,7 +8,7 @@ const schema = {
type: 'document',
icon: Icon,
fields: [],
initialValue: () => ({
initialValues: () => ({
role: 'Developer'
})
},
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/desk-tool/test/mocks/schema.js
Expand Up @@ -122,7 +122,7 @@ function post() {
media: 'mainImage'
}
},
initialValue: {
initialValues: {
slug: {_type: 'slug', current: 'default-slug'}
},
orderings: [
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/initial-value-templates/src/builder.ts
Expand Up @@ -18,7 +18,7 @@ function defaultTemplateForType(
schemaType: type.name,
title: type.title || type.name,
icon: type.icon,
value: type.initialValue || {_type: type.name}
value: type.initialValues || {_type: type.name}
})
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ export interface SchemaType {
to?: SchemaField[]
fields?: SchemaField[]
orderings?: Ordering[]
initialValue?: Function | {[key: string]: any}
initialValues?: Function | {[key: string]: any}
preview?: {
select?: PreviewFields
prepare?: PreviewPreparer
Expand Down
Expand Up @@ -8,7 +8,7 @@ const schema = {
type: 'document',
icon: Icon,
fields: [],
initialValue: () => ({
initialValues: () => ({
role: 'Developer'
})
},
Expand Down
12 changes: 8 additions & 4 deletions packages/@sanity/schema/src/sanity/validation/types/document.js
Expand Up @@ -4,14 +4,18 @@ import object from './object'

export default (typeDefinition, visitorContext) => {
const typeDef = object(typeDefinition, visitorContext)
const {initialValue} = typeDef
const {initialValue, initialValues} = typeDef

const hasInitialValue = typeof initialValue !== 'undefined'
if (hasInitialValue && !isPlainObject(initialValue) && typeof initialValue !== 'function') {
const hasInitialValues = typeof initialValues !== 'undefined'
if (hasInitialValues && !isPlainObject(initialValues) && typeof initialValues !== 'function') {
typeDef._problems.push(
error(`The "initialValue" property must be either a plain object or a function`)
error(`The "initialValues" property must be either a plain object or a function`)
)
}

if (typeof initialValue !== 'undefined') {
typeDef._problems.push(error(`Found property "initialValue" - did you mean "initialValues"?`))
}

return typeDef
}
Expand Up @@ -131,7 +131,7 @@ Object {
},
],
"icon": [Function],
"initialValue": Object {
"initialValues": Object {
"slug": Object {
"_type": "slug",
"current": "default-slug",
Expand Down Expand Up @@ -306,7 +306,7 @@ Object {
},
],
"icon": [Function],
"initialValue": Object {
"initialValues": Object {
"slug": Object {
"_type": "slug",
"current": "default-slug",
Expand Down Expand Up @@ -429,7 +429,7 @@ Object {
},
],
"icon": [Function],
"initialValue": Object {
"initialValues": Object {
"slug": Object {
"_type": "slug",
"current": "default-slug",
Expand Down
Expand Up @@ -630,7 +630,7 @@ Array [
},
],
"icon": [Function],
"initialValue": Object {
"initialValues": Object {
"slug": Object {
"_type": "slug",
"current": "default-slug",
Expand Down Expand Up @@ -1031,7 +1031,7 @@ Array [
},
],
"icon": [Function],
"initialValue": Object {
"initialValues": Object {
"slug": Object {
"_type": "slug",
"current": "default-slug",
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/structure/test/mocks/schema.js
Expand Up @@ -122,7 +122,7 @@ function post() {
media: 'mainImage'
}
},
initialValue: {
initialValues: {
slug: {_type: 'slug', current: 'default-slug'}
},
orderings: [
Expand Down
2 changes: 1 addition & 1 deletion packages/test-studio/schemas/author.js
Expand Up @@ -100,7 +100,7 @@ export default {
}
],

initialValue: () =>
initialValues: () =>
new Promise(resolve =>
setTimeout(resolve, 2500, {
name: 'Foo',
Expand Down
2 changes: 1 addition & 1 deletion packages/test-studio/schemas/book.js
Expand Up @@ -106,7 +106,7 @@ export default {
})
}
},
initialValue: {
initialValues: {
title: 'Foo'
}
}

0 comments on commit 10c35c1

Please sign in to comment.