Skip to content

Commit

Permalink
Add info about custom setters
Browse files Browse the repository at this point in the history
  • Loading branch information
dacharyc committed Jul 10, 2024
1 parent ac55416 commit e7cf6f8
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In the following code, the private ``email`` property is stored in the database,
but the public ``Email`` property, which provides validation, is not persisted.
71 changes: 71 additions & 0 deletions source/includes/sdk-examples/model-data/define-custom-setters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.cpp
:language: cpp
:copyable: false

- id: csharp
content: |

.. literalinclude:: /examples/generated/dotnet/Objects.snippet.custom-setter.cs
:language: csharp

- id: dart
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.dart
:language: dart
:copyable: false

- id: java
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.java
:language: java
:copyable: false

- id: java-kotlin
content: |

.. literalinclude:: /examples/MissingPlaceholders/example-java-kotlin.kt
:language: kotlin
:copyable: false

- id: javascript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.js
:language: javascript
:copyable: false

- id: kotlin
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.kt
:language: kotlin
:copyable: false

- id: objectivec
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.m
:language: objectivec
:copyable: false

- id: swift
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.swift
:language: swift
:copyable: false

- id: typescript
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.ts
:language: typescript
:copyable: false
60 changes: 59 additions & 1 deletion source/sdk/model-data/object-models.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,55 @@ first access, so will never be nil.

.. include:: /includes/sdk-examples/model-data/define-default-value-for-property.rst

.. _sdks-custom-setters:

Define Custom Setters
~~~~~~~~~~~~~~~~~~~~~

For some platforms and languages, the idiomatic developer experience involves
defining custom setters. The SDK does not directly persist properties using
custom setters. Instead, you can store the property value in a private property,
and then map that value to a public property that uses the custom setter.

The SDK stores the private property, while you modify its value through the
public property.

.. tabs-drivers::

.. tab::
:tabid: cpp-sdk

.. tab::
:tabid: csharp

.. include:: /includes/api-details/csharp/model-data/object-models-define-custom-setters-description.rst

.. tab::
:tabid: dart

.. tab::
:tabid: java

.. tab::
:tabid: java-kotlin

.. tab::
:tabid: javascript

.. tab::
:tabid: kotlin

.. tab::
:tabid: objectivec

.. tab::
:tabid: swift

.. tab::
:tabid: typescript

.. include:: /includes/sdk-examples/model-data/define-custom-setters.rst

.. _sdks-model-unstructured-data:

Model Unstructured Data
Expand Down Expand Up @@ -1252,7 +1301,16 @@ a projection to make data available in a specific form, but persist it in a
different form.

For example, you might want to work with persisted data in a different way in
a view model or based on certain business logic.
a view model or based on certain business logic. This simplifies using and
testing SDK objects in your application.

With projection, you can use a subset of your object's properties directly in
the UI, or transform them. When you use a projection for this, you get all the
benefits of the SDK's live objects:

- The class-projected object live updates
- You can observe it for changes
- You can apply changes directly to the properties in write transactions

Projection is currently only available in the Swift SDK.

Expand Down
15 changes: 15 additions & 0 deletions source/sdk/model-data/property-types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ Define a Set Property

Define a Dictionary Property
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. _sdks-relationship-property-types:

Relationship Property Types
---------------------------

.. _sdks-other-property-types:

Other Property Types
--------------------

.. _sdks-enum-property:

Define an Enum Property
~~~~~~~~~~~~~~~~~~~~~~~

0 comments on commit e7cf6f8

Please sign in to comment.