docs: Document using models on the client only - #739
Open
abdulawalarif wants to merge 1 commit into
Open
Conversation
1 task
|
|
||
| ```yaml | ||
| class: CartItem | ||
| immutable: true |
Contributor
There was a problem hiding this comment.
Suggestion: drop immutable: true from this example. The page only introduces immutability further down, and the sentence below the example already points readers there when they need value equality.
Suggested change
| immutable: true |
|
|
||
| You can define models that you only use in the Flutter app, for example to hold local UI state or form data. Leave `serverOnly` unset so the class is generated for the client. There is no separate `clientOnly` flag. | ||
|
|
||
| Place the `.spy.yaml` file anywhere in the server's `lib` directory, run code generation, and import the class from the client package. |
Contributor
There was a problem hiding this comment.
Suggestion: mirror how the intro of this page describes code generation, so both spots teach the same loop.
Suggested change
| Place the `.spy.yaml` file anywhere in the server's `lib` directory, run code generation, and import the class from the client package. | |
| Place the `.spy.yaml` file anywhere in the server's `lib` directory. With `serverpod start` running, saving the file regenerates the code; otherwise run `serverpod generate`. Then import the class from the client package. |
| ``` | ||
|
|
||
| ```dart | ||
| import 'package:my_project_client/my_project_client.dart'; |
Contributor
There was a problem hiding this comment.
Suggestion: the other import examples in the docs use your_client, so keeping that name here helps readers connect them.
Suggested change
| import 'package:my_project_client/my_project_client.dart'; | |
| import 'package:your_client/your_client.dart'; |
| var item = CartItem(productId: 'sku-1', quantity: 2); | ||
| ``` | ||
|
|
||
| The class is also generated on the server. That is harmless: omit the `table` key so no database table is created, and you do not need to use the class in any endpoint. Set `immutable: true` if you want value equality for Flutter state management. See [Immutable classes](#immutable-classes). |
Contributor
There was a problem hiding this comment.
Suggestion: this reads as if omitting table is what makes the server copy harmless; the two facts sit side by side rather than cause and effect.
Suggested change
| The class is also generated on the server. That is harmless: omit the `table` key so no database table is created, and you do not need to use the class in any endpoint. Set `immutable: true` if you want value equality for Flutter state management. See [Immutable classes](#immutable-classes). | |
| The class is also generated on the server, which is harmless: without a `table` key no database table is created, and nothing requires you to use the class in an endpoint. Set `immutable: true` if you want value equality for Flutter state management. See [Immutable classes](#immutable-classes). |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Working with models covered
serverOnlyand fieldscope, but not that you can define models you only use in Flutter. There is noclientOnlyflag. Place the YAML in the server package as usual; generating the class on the server as well is harmless.Fixes serverpod/serverpod#3670
Changes
.spy.yamlfile in the server package, running code generation, and importing the class from the client package.tableavoids creating a database table, and point toimmutable: trueand shared packages.Reference