diff --git a/examples/react-native/legacy/bluehawk.sh b/examples/react-native/legacy/bluehawk.sh index 4e04a3909f..50b418a405 100755 --- a/examples/react-native/legacy/bluehawk.sh +++ b/examples/react-native/legacy/bluehawk.sh @@ -10,6 +10,6 @@ JS_GENERATED_EXAMPLES=$PROJECT/source/examples/generated/react-native/js TS_GENERATED_EXAMPLES=$PROJECT/source/examples/generated/react-native/ts echo $JS_GENERATED_EXAMPLES -bluehawk snip $JS_RN_EXAMPLES -o $JS_GENERATED_EXAMPLES +npx bluehawk snip $JS_RN_EXAMPLES -o $JS_GENERATED_EXAMPLES -bluehawk snip $TS_RN_EXAMPLES -o $TS_GENERATED_EXAMPLES +npx bluehawk snip $TS_RN_EXAMPLES -o $TS_GENERATED_EXAMPLES diff --git a/examples/react-native/v12/scripts/bluehawk-one.sh b/examples/react-native/v12/scripts/bluehawk-one.sh index 06a1aefc49..580aedf03c 100755 --- a/examples/react-native/v12/scripts/bluehawk-one.sh +++ b/examples/react-native/v12/scripts/bluehawk-one.sh @@ -44,7 +44,7 @@ then # Bluehawk a single file echo "${GREEN_BG_BOLD} Bluehawk: ${CLEAR} ${GREEN}Generate samples from '$FILE_NAME' ${CLEAR}" -bluehawk snip $INPUT_FILE -o $OUTPUT_DIRECTORY --format=rst +npx bluehawk snip $INPUT_FILE -o $OUTPUT_DIRECTORY --format=rst # TODO: There's probably a more idiomatic way to do this results filtering. GENERATED_FILES=$(find $OUTPUT_DIRECTORY -type f | grep -i $BASE_FILE_NAME) diff --git a/examples/react-native/v12/scripts/bluehawk.sh b/examples/react-native/v12/scripts/bluehawk.sh index c16976a40d..6d14d996b5 100755 --- a/examples/react-native/v12/scripts/bluehawk.sh +++ b/examples/react-native/v12/scripts/bluehawk.sh @@ -25,7 +25,7 @@ OUTPUT_DIRECTORY=$PROJECT/source/examples/generated/react-native/v12 # standard bluehawking echo "${GREEN_BG_BOLD}Bluehawk: ${CLEAR} ${GREEN} Generate React Native v12 examples ${CLEAR}" -bluehawk snip $INPUT_DIRECTORY -o $OUTPUT_DIRECTORY --format=rst +npx bluehawk snip $INPUT_DIRECTORY -o $OUTPUT_DIRECTORY --format=rst FILES_TO_REMOVE=$(find $OUTPUT_DIRECTORY -type f -not -name "*.rst") diff --git a/source/examples/generated/react-native/js/delete.test.snippet.crud-delete-multiple-objects.jsx b/source/examples/generated/react-native/js/delete.test.snippet.crud-delete-multiple-objects.jsx index 6eac198c1a..d78a3362dd 100644 --- a/source/examples/generated/react-native/js/delete.test.snippet.crud-delete-multiple-objects.jsx +++ b/source/examples/generated/react-native/js/delete.test.snippet.crud-delete-multiple-objects.jsx @@ -3,7 +3,9 @@ const DogList = () => { const myDogs = useQuery(Dog); const deleteAllYoungDogObjects = () => { - const youngDogs = myDogs.filtered('age < 3'); + const youngDogs = useQuery(Dog, dogs => { + return dogs.filtered('age < 3'); + }); realm.write(() => { realm.delete(youngDogs); }); diff --git a/source/examples/generated/react-native/js/dictionary-test.snippet.delete-members-of-a-dictionary.jsx b/source/examples/generated/react-native/js/dictionary-test.snippet.delete-members-of-a-dictionary.jsx index eeee773907..51b6064e56 100644 --- a/source/examples/generated/react-native/js/dictionary-test.snippet.delete-members-of-a-dictionary.jsx +++ b/source/examples/generated/react-native/js/dictionary-test.snippet.delete-members-of-a-dictionary.jsx @@ -1,7 +1,11 @@ const HomeInfo = ({homeOwnerName}) => { const realm = useRealm(); - const homeOwner = useQuery(HomeOwner).filtered( - `name == '${homeOwnerName}'`, + const homeOwner = useQuery( + HomeOwner, + homeOwners => { + return homeOwners.filtered(`name == '${homeOwnerName}'`); + }, + [homeOwnerName], )[0]; const deleteExtraHomeInfo = () => { diff --git a/source/examples/generated/react-native/js/dictionary-test.snippet.query-objects-with-dictionary.jsx b/source/examples/generated/react-native/js/dictionary-test.snippet.query-objects-with-dictionary.jsx index 3d31b1d04b..081b8f4285 100644 --- a/source/examples/generated/react-native/js/dictionary-test.snippet.query-objects-with-dictionary.jsx +++ b/source/examples/generated/react-native/js/dictionary-test.snippet.query-objects-with-dictionary.jsx @@ -4,17 +4,22 @@ const HomeList = () => { // run the `.filtered()` method on all the returned homeOwners to // find all homeOwners that have a house with a listed price - const listedPriceHomes = homeOwners.filtered('home.@keys = "price"'); + const listedPriceHomes = useQuer(HomeOwner, homeOwners => { + return homeOwners.filtered('home.@keys = "price"'); + }); // run the `.filtered()` method on all the returned homeOwners to // find the house with the address "Summerhill St." - const summerHillHouse = homeOwners.filtered( - 'home["address"] = "Summerhill St."', - )[0].home; + const summerHillHouse = useQuery(HomeOwner, homeOwners => { + return homeOwner.filtered('home["address"] = "Summerhill St."'); + })[0].home; // run the `.filtered()` method on all the returned homeOwners to // find the first house that has any field with a value of 'red' - const redHouse = homeOwners.filtered('home.@values = "red"')[0].home; + const redHouse = useQuery(HomeOwner, homeOwners => { + return homeOwners.filtered('home.@values = "red"'); + })[0].home; + return ( All homes: diff --git a/source/examples/generated/react-native/js/dictionary-test.snippet.update-a-dictionary.jsx b/source/examples/generated/react-native/js/dictionary-test.snippet.update-a-dictionary.jsx index 57fd0bc8c2..a3fef5da31 100644 --- a/source/examples/generated/react-native/js/dictionary-test.snippet.update-a-dictionary.jsx +++ b/source/examples/generated/react-native/js/dictionary-test.snippet.update-a-dictionary.jsx @@ -1,8 +1,12 @@ const UpdateHome = ({homeOwnerName}) => { const [address, setAddress] = useState(''); const realm = useRealm(); - const homeOwner = useQuery(HomeOwner).filtered( - `name == '${homeOwnerName}'`, + const homeOwner = useQuery( + HomeOwner, + homeOwners => { + return homeOwners.filtered(`name == '${homeOwnerName}'`); + }, + [homeOwnerName], )[0]; const updateAddress = () => { diff --git a/source/examples/generated/react-native/js/embedded-objects-test.snippet.delete-embedded-object.jsx b/source/examples/generated/react-native/js/embedded-objects-test.snippet.delete-embedded-object.jsx index ecc8f4b975..08c2a2da62 100644 --- a/source/examples/generated/react-native/js/embedded-objects-test.snippet.delete-embedded-object.jsx +++ b/source/examples/generated/react-native/js/embedded-objects-test.snippet.delete-embedded-object.jsx @@ -1,12 +1,19 @@ const ContactInfo = ({contactCity, postalCode}) => { - const contacts = useQuery(Contact); - const parentsToDelete = contacts.filtered( - `address.city == '${contactCity}'`, + const realm = useRealm(); + const parentsToDelete = useQuery( + Contact, + contacts => { + return contacts.filtered(`address.city == '${contactCity}'`); + }, + [contactCity], ); - const embeddedToDelete = contacts.filtered( - `address.postalCode == '${postalCode}'`, + const embeddedToDelete = useQuery( + Contact, + contacts => { + return contacts.filtered(`address.postalCode == '${postalCode}'`); + }, + [postalCode], ); - const realm = useRealm(); const deleteParentObject = () => { realm.write(() => { diff --git a/source/examples/generated/react-native/js/embedded-objects-test.snippet.query-embedded-object.jsx b/source/examples/generated/react-native/js/embedded-objects-test.snippet.query-embedded-object.jsx index b1b81005c8..75f8111f14 100644 --- a/source/examples/generated/react-native/js/embedded-objects-test.snippet.query-embedded-object.jsx +++ b/source/examples/generated/react-native/js/embedded-objects-test.snippet.query-embedded-object.jsx @@ -1,11 +1,12 @@ const ContactList = ({postalCode}) => { - // Query for all Contact objects - const contacts = useQuery(Contact); - // Run the `.filtered()` method on all the returned Contacts to get // contacts with a specific postal code. - const contactsInArea = contacts.filtered( - `address.postalCode == '${postalCode}'`, + const contactsInArea = useQuery( + Contact, + contacts => { + return contacts.filtered(`address.postalCode == '${postalCode}'`); + }, + [postalCode], ); if (contactsInArea.length) { diff --git a/source/examples/generated/react-native/js/mixed-test.snippet.query-mixed-object.jsx b/source/examples/generated/react-native/js/mixed-test.snippet.query-mixed-object.jsx index aca8c8f71f..565e18149b 100644 --- a/source/examples/generated/react-native/js/mixed-test.snippet.query-mixed-object.jsx +++ b/source/examples/generated/react-native/js/mixed-test.snippet.query-mixed-object.jsx @@ -1,7 +1,13 @@ const CatInfoCard = ({catName}) => { // To query for the cat's birthDate, filter for their name to retrieve the realm object. // Use dot notation to access the birthDate property. - const cat = useQuery(Cat).filtered(`name = '${catName}'`)[0]; + const cat = useQuery( + Cat, + cats => { + return cats.filtered(`name = '${catName}'`); + }, + [catName], + )[0]; const catBirthDate = cat.birthDate; if (cat) { diff --git a/source/examples/generated/react-native/js/quickstart-find-sort-filter.test.snippet.find-sort-filter.jsx b/source/examples/generated/react-native/js/quickstart-find-sort-filter.test.snippet.find-sort-filter.jsx index 9c96694320..b6e8e566df 100644 --- a/source/examples/generated/react-native/js/quickstart-find-sort-filter.test.snippet.find-sort-filter.jsx +++ b/source/examples/generated/react-native/js/quickstart-find-sort-filter.test.snippet.find-sort-filter.jsx @@ -45,7 +45,13 @@ const FindSortFilterComponent = ({objectPrimaryKey}) => { const filterProfiles = (filter, letter) => { // Use [c] for case-insensitivity. - const filtered = profiles.filtered(`name ${filter}[c] "${letter}"`); + const filtered = useQuery( + Profile, + profiles => { + return profiles.filtered(`name ${filter}[c] "${letter}"`); + }, + [filter, letter], + ); setAllProfiles(filtered); }; diff --git a/source/examples/generated/react-native/js/read.test.snippet.crud-read-filter-data.jsx b/source/examples/generated/react-native/js/read.test.snippet.crud-read-filter-data.jsx index 4b27d52072..7785197400 100644 --- a/source/examples/generated/react-native/js/read.test.snippet.crud-read-filter-data.jsx +++ b/source/examples/generated/react-native/js/read.test.snippet.crud-read-filter-data.jsx @@ -1,16 +1,17 @@ const TaskList = () => { - // retrieve the set of Task objects - const tasks = useQuery(Task); - // filter for tasks with a high priority - const highPriorityTasks = tasks.filtered('priority >= $0', 4); + const highPriorityTasks = useQuery(Task, tasks => { + return tasks.filtered('priority >= $0', 4); + }); // filter for tasks that have just-started or short-running progress - const lowProgressTasks = tasks.filtered( - '$0 <= progressMinutes && progressMinutes < $1', - 1, - 10, - ); + const lowProgressTasks = useQuery(Task, tasks => { + return tasks.filtered( + '$0 <= progressMinutes && progressMinutes < $1', + 1, + 10, + ); + }); return ( <> diff --git a/source/examples/generated/react-native/js/relationships-test.snippet.query-backlinks.jsx b/source/examples/generated/react-native/js/relationships-test.snippet.query-backlinks.jsx index e32e6cf008..823b7915e3 100644 --- a/source/examples/generated/react-native/js/relationships-test.snippet.query-backlinks.jsx +++ b/source/examples/generated/react-native/js/relationships-test.snippet.query-backlinks.jsx @@ -1,12 +1,11 @@ const PostsByYoungUsers = () => { - const posts = useQuery(Post); - const postsByYoungUsers = useMemo(() => { + const postsByYoungUsers = useQuery(Post, posts => { return posts.filtered( '@links.User.posts.birthdate >= 2000-01-01@00:00:00:0', ); - }, [posts]); + }); - if (!posts) return The post was not found.; + if (!postsByYoungUsers) return The post was not found.; return ( Posts By Young Users diff --git a/source/examples/generated/react-native/js/sets-test.snippet.add-items-to-set.jsx b/source/examples/generated/react-native/js/sets-test.snippet.add-items-to-set.jsx index 0a1e10457e..61e46c41fd 100644 --- a/source/examples/generated/react-native/js/sets-test.snippet.add-items-to-set.jsx +++ b/source/examples/generated/react-native/js/sets-test.snippet.add-items-to-set.jsx @@ -1,8 +1,12 @@ const AddInventoryToCharacter = ({characterName}) => { const realm = useRealm(); const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const addInventoryItem = () => { diff --git a/source/examples/generated/react-native/js/sets-test.snippet.check-set-items-and-size.jsx b/source/examples/generated/react-native/js/sets-test.snippet.check-set-items-and-size.jsx index d449e4c967..f961479091 100644 --- a/source/examples/generated/react-native/js/sets-test.snippet.check-set-items-and-size.jsx +++ b/source/examples/generated/react-native/js/sets-test.snippet.check-set-items-and-size.jsx @@ -1,7 +1,11 @@ const QueryCharacterInventory = ({characterName}) => { const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const queryCharacterInventory = () => { diff --git a/source/examples/generated/react-native/js/sets-test.snippet.remove-items-from-set.jsx b/source/examples/generated/react-native/js/sets-test.snippet.remove-items-from-set.jsx index 6be7bf1da7..6a2add663b 100644 --- a/source/examples/generated/react-native/js/sets-test.snippet.remove-items-from-set.jsx +++ b/source/examples/generated/react-native/js/sets-test.snippet.remove-items-from-set.jsx @@ -1,8 +1,12 @@ const RemoveInventoryFromCharacter = ({characterName}) => { const realm = useRealm(); const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const removeInventoryItem = () => { diff --git a/source/examples/generated/react-native/js/sets-test.snippet.traverse-a-set.jsx b/source/examples/generated/react-native/js/sets-test.snippet.traverse-a-set.jsx index 2e593e31f5..f6a754153f 100644 --- a/source/examples/generated/react-native/js/sets-test.snippet.traverse-a-set.jsx +++ b/source/examples/generated/react-native/js/sets-test.snippet.traverse-a-set.jsx @@ -3,8 +3,12 @@ const TraverseCharacterInventory = ({characterName}) => { const [inventoryItem, setInventoryItem] = useState(''); const [inventory, setInventory] = useState([]); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const addInventoryItem = () => { diff --git a/source/examples/generated/react-native/ts/Profile.snippet.ts-profile-schema.ts b/source/examples/generated/react-native/ts/Profile.snippet.ts-profile-schema.ts index b78fb553dd..2fe3dbf919 100644 --- a/source/examples/generated/react-native/ts/Profile.snippet.ts-profile-schema.ts +++ b/source/examples/generated/react-native/ts/Profile.snippet.ts-profile-schema.ts @@ -1,12 +1,12 @@ class Profile extends Realm.Object { - _id!: Realm.BSON.UUID; + _id!: Realm.BSON.ObjectId; name!: string; static schema: ObjectSchema = { name: 'Profile', primaryKey: '_id', properties: { - _id: 'uuid', + _id: 'objectId', name: 'string', }, }; diff --git a/source/examples/generated/react-native/ts/add-query-to-subs.test.snippet.add-query.tsx b/source/examples/generated/react-native/ts/add-query-to-subs.test.snippet.add-query.tsx index 95e5f35517..4581669f4a 100644 --- a/source/examples/generated/react-native/ts/add-query-to-subs.test.snippet.add-query.tsx +++ b/source/examples/generated/react-native/ts/add-query-to-subs.test.snippet.add-query.tsx @@ -1,31 +1,28 @@ import React, {useEffect} from 'react'; -// get realm context from createRealmContext() -import {RealmContext} from '../RealmConfig'; import {Text, FlatList} from 'react-native'; - -const {useRealm} = RealmContext; +import {useRealm, useQuery} from '@realm/react'; function SubscriptionManager() { const realm = useRealm(); - const seenBirds = realm.objects('Bird').filtered('haveSeen == true'); + const seenBirds = useQuery(Bird, birds => { + return birds.filtered('haveSeen == true'); + }); useEffect(() => { - realm.subscriptions.update((mutableSubs, realm) => { - // Create subscription query - const seenBirdsSubQuery = realm - .objects('Bird') - .filtered('haveSeen == true'); + realm.subscriptions.update( + (mutableSubs: Realm.App.Sync.MutableSubscriptionSet) => { - // Create subscription for filtered results. - mutableSubs.add(seenBirdsSubQuery, {name: 'seenBirds'}); - }); + // Create subscription for filtered collection. + mutableSubs.add(seenBirds, {name: 'seenBirds'}); + }, + ); }); return ( bird._id.toString()} - renderItem={({item}) => {item._id}} + keyExtractor={item => item._id.toString()} + renderItem={({item}) => {item._id.toString()}} /> ); } diff --git a/source/examples/generated/react-native/ts/check-subs-status.test.snippet.check-sub-status.tsx b/source/examples/generated/react-native/ts/check-subs-status.test.snippet.check-sub-status.tsx index 855e095b93..3e11771043 100644 --- a/source/examples/generated/react-native/ts/check-subs-status.test.snippet.check-sub-status.tsx +++ b/source/examples/generated/react-native/ts/check-subs-status.test.snippet.check-sub-status.tsx @@ -1,18 +1,22 @@ import React, {useEffect} from 'react'; import {Text, View} from 'react-native'; -// get realm context from createRealmContext() -import {RealmContext} from '../RealmConfig'; - -const {useRealm, useQuery} = RealmContext; +import {useRealm, useQuery} from '@realm/react'; +import {Bird} from '../Models/Bird'; function SubscriptionManager() { const realm = useRealm(); + const seenBirds = useQuery(Bird, birds => { + return birds.filtered('haveSeen == true'); + }); useEffect(() => { - realm.subscriptions.update((mutableSubs, realm) => { - // Create subscription for filtered results. - mutableSubs.add(realm.objects('Bird').filtered('haveSeen == true')); - }); + realm.subscriptions.update( + (mutableSubs: Realm.App.Sync.MutableSubscriptionSet) => { + + // Create subscription for filtered collection. + mutableSubs.add(seenBirds, {name: 'seenBirds'}); + }, + ); }); // Returns state of all subscriptions, not individual subscriptions. @@ -22,7 +26,9 @@ function SubscriptionManager() { return ( - Status of all subscriptions: {allSubscriptionState} + + Status of all subscriptions: {allSubscriptionState} + ); } diff --git a/source/examples/generated/react-native/ts/delete.test.snippet.crud-delete-multiple-objects.tsx b/source/examples/generated/react-native/ts/delete.test.snippet.crud-delete-multiple-objects.tsx index 6eac198c1a..d78a3362dd 100644 --- a/source/examples/generated/react-native/ts/delete.test.snippet.crud-delete-multiple-objects.tsx +++ b/source/examples/generated/react-native/ts/delete.test.snippet.crud-delete-multiple-objects.tsx @@ -3,7 +3,9 @@ const DogList = () => { const myDogs = useQuery(Dog); const deleteAllYoungDogObjects = () => { - const youngDogs = myDogs.filtered('age < 3'); + const youngDogs = useQuery(Dog, dogs => { + return dogs.filtered('age < 3'); + }); realm.write(() => { realm.delete(youngDogs); }); diff --git a/source/examples/generated/react-native/ts/dictionary-test.snippet.delete-members-of-a-dictionary.tsx b/source/examples/generated/react-native/ts/dictionary-test.snippet.delete-members-of-a-dictionary.tsx index d1bf060b56..00bed4e1bc 100644 --- a/source/examples/generated/react-native/ts/dictionary-test.snippet.delete-members-of-a-dictionary.tsx +++ b/source/examples/generated/react-native/ts/dictionary-test.snippet.delete-members-of-a-dictionary.tsx @@ -1,8 +1,12 @@ const HomeInfo = ({homeOwnerName}: {homeOwnerName: string}) => { const realm = useRealm(); - const homeOwner = useQuery(HomeOwner).filtered( - `name == '${homeOwnerName}'`, + const homeOwner = useQuery( + HomeOwner, + homeOwners => { + return homeOwners.filtered(`name == '${homeOwnerName}'`); + }, + [homeOwnerName], )[0]; const deleteExtraHomeInfo = () => { diff --git a/source/examples/generated/react-native/ts/dictionary-test.snippet.query-objects-with-dictionary.tsx b/source/examples/generated/react-native/ts/dictionary-test.snippet.query-objects-with-dictionary.tsx index 3d31b1d04b..d95a4239c7 100644 --- a/source/examples/generated/react-native/ts/dictionary-test.snippet.query-objects-with-dictionary.tsx +++ b/source/examples/generated/react-native/ts/dictionary-test.snippet.query-objects-with-dictionary.tsx @@ -4,17 +4,22 @@ const HomeList = () => { // run the `.filtered()` method on all the returned homeOwners to // find all homeOwners that have a house with a listed price - const listedPriceHomes = homeOwners.filtered('home.@keys = "price"'); + const listedPriceHomes = useQuery(HomeOwner, homeOwners => { + return homeOwners.filtered('home.@keys = "price"'); + }); // run the `.filtered()` method on all the returned homeOwners to // find the house with the address "Summerhill St." - const summerHillHouse = homeOwners.filtered( - 'home["address"] = "Summerhill St."', - )[0].home; + const summerHillHouse = useQuery(HomeOwner, homeOwners => { + return homeOwners.filtered('home["address"] = "Summerhill St."'); + })[0].home; // run the `.filtered()` method on all the returned homeOwners to // find the first house that has any field with a value of 'red' - const redHouse = homeOwners.filtered('home.@values = "red"')[0].home; + const redHouse = useQuery(HomeOwner, homeOwners => { + return homeOwners.filtered('home.@values = "red"'); + })[0].home; + return ( All homes: diff --git a/source/examples/generated/react-native/ts/dictionary-test.snippet.update-a-dictionary.tsx b/source/examples/generated/react-native/ts/dictionary-test.snippet.update-a-dictionary.tsx index 0132bf8f2a..50d814e0ed 100644 --- a/source/examples/generated/react-native/ts/dictionary-test.snippet.update-a-dictionary.tsx +++ b/source/examples/generated/react-native/ts/dictionary-test.snippet.update-a-dictionary.tsx @@ -1,8 +1,12 @@ const UpdateHome = ({homeOwnerName}: {homeOwnerName: string}) => { const [address, setAddress] = useState(''); const realm = useRealm(); - const homeOwner = useQuery(HomeOwner).filtered( - `name == '${homeOwnerName}'`, + const homeOwner = useQuery( + HomeOwner, + homeOwners => { + return homeOwners.filtered(`name == '${homeOwnerName}'`); + }, + [homeOwnerName], )[0]; const updateAddress = () => { diff --git a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.delete-embedded-object.tsx b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.delete-embedded-object.tsx index ab3a88e66e..512e3aae7e 100644 --- a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.delete-embedded-object.tsx +++ b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.delete-embedded-object.tsx @@ -4,13 +4,12 @@ type ContactInfoProps = { }; const ContactInfo = ({contactCity, postalCode}: ContactInfoProps) => { - const contacts = useQuery(Contact); - const parentsToDelete = contacts.filtered( - `address.city == '${contactCity}'`, - ); - const embeddedToDelete = contacts.filtered( - `address.postalCode == '${postalCode}'`, - ); + const parentsToDelete = useQuery(Contact, contacts => { + return contacts.filtered(`address.city == '${contactCity}'`); + }); + const embeddedToDelete = useQuery(Contact, contacts => { + return contacts.filtered(`address.postalCode == '${postalCode}'`); + }); const realm = useRealm(); const deleteParentObject = () => { diff --git a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.overwrite-embedded-object.tsx b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.overwrite-embedded-object.tsx index 37e0664bd4..d87b12f325 100644 --- a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.overwrite-embedded-object.tsx +++ b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.overwrite-embedded-object.tsx @@ -1,5 +1,7 @@ -const OverwriteContact = ({contactId}: { - contactId: Realm.BSON.ObjectId +const OverwriteContact = ({ + contactId, +}: { + contactId: Realm.BSON.ObjectId; }) => { const [street, setStreet] = useState(''); const [city, setCity] = useState(''); diff --git a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.query-embedded-object.tsx b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.query-embedded-object.tsx index f05b22c508..ca5e93cab9 100644 --- a/source/examples/generated/react-native/ts/embedded-objects-test.snippet.query-embedded-object.tsx +++ b/source/examples/generated/react-native/ts/embedded-objects-test.snippet.query-embedded-object.tsx @@ -1,18 +1,14 @@ const ContactList = ({postalCode}: {postalCode: string}) => { - // Query for all Contact objects - const contacts = useQuery(Contact); - - // Run the `.filtered()` method on all the returned Contacts to get + // Run the `.filtered()` method on all Contact objects to get // contacts with a specific postal code. - const contactsInArea = contacts.filtered( - `address.postalCode == '${postalCode}'`, - ); + const contactsInArea = useQuery(Contact, contacts => { + return contacts.filtered(`address.postalCode == '${postalCode}'`); + }); if (contactsInArea.length) { return ( <> { {item.name}; diff --git a/source/examples/generated/react-native/ts/get-subscriptions.test.snippet.get-subscriptions.tsx b/source/examples/generated/react-native/ts/get-subscriptions.test.snippet.get-subscriptions.tsx index 3d98fe6898..3e84ca8232 100644 --- a/source/examples/generated/react-native/ts/get-subscriptions.test.snippet.get-subscriptions.tsx +++ b/source/examples/generated/react-native/ts/get-subscriptions.test.snippet.get-subscriptions.tsx @@ -1,30 +1,38 @@ -import React, {useEffect} from 'react'; -// get realm context from createRealmContext() -import {RealmContext} from '../RealmConfig'; +import React, {useEffect, useState} from 'react'; import {Text, FlatList} from 'react-native'; - -const {useRealm, useQuery} = RealmContext; +import {useRealm, useQuery} from '@realm/react'; +import {Bird} from '../Models/Bird'; function SubscriptionManager() { const realm = useRealm(); - // Returns a subscription set that contains all subscriptions. - const allSubscriptions = realm.subscriptions; - // Pass object model to useQuery and filter results. // This does not create a subscription. - const seenBirds = useQuery('Bird').filtered('haveSeen == true'); + const seenBirds = useQuery(Bird, birds => { + return birds.filtered('haveSeen == true'); + }); + + const [subscriptions, setSubcriptions] = useState< + App.Sync.SubscriptionSet | undefined + >(); useEffect(() => { - realm.subscriptions.update(mutableSubs => { + const createSubscription = async () => { // Create subscription for filtered results. - mutableSubs.add(seenBirds); - }); - }); + await realm.subscriptions.update(mutableSubs => { + mutableSubs.add(seenBirds, {name: 'seen birds'}); + }); + }; + + createSubscription().catch(console.error); + + // Set to state variable. + setSubcriptions(realm.subscriptions); + }, []); return ( subscription.id.toString()} renderItem={({item}) => {item.name}} /> diff --git a/source/examples/generated/react-native/ts/mixed-test.snippet.query-mixed-object.tsx b/source/examples/generated/react-native/ts/mixed-test.snippet.query-mixed-object.tsx index 6f9329020a..1af40802bd 100644 --- a/source/examples/generated/react-native/ts/mixed-test.snippet.query-mixed-object.tsx +++ b/source/examples/generated/react-native/ts/mixed-test.snippet.query-mixed-object.tsx @@ -3,7 +3,13 @@ type CatInfoCardProps = {catName: string}; const CatInfoCard = ({catName}: CatInfoCardProps) => { // To query for the cat's birthDate, filter for their name to retrieve the realm object. // Use dot notation to access the birthDate property. - const cat = useQuery(Cat).filtered(`name = '${catName}'`)[0]; + const cat = useQuery( + Cat, + cats => { + return cats.filtered(`name = '${catName}'`); + }, + [catName], + )[0]; const catBirthDate = cat.birthDate; if (cat) { diff --git a/source/examples/generated/react-native/ts/mixed-test.snippet.type-check.tsx b/source/examples/generated/react-native/ts/mixed-test.snippet.type-check.tsx index d64c3b7dd2..6cbc04e94d 100644 --- a/source/examples/generated/react-native/ts/mixed-test.snippet.type-check.tsx +++ b/source/examples/generated/react-native/ts/mixed-test.snippet.type-check.tsx @@ -11,7 +11,13 @@ const isString = ( type CatInfoCardProps = {catName: string}; const CatInfoCard = ({catName}: CatInfoCardProps) => { - const cat = useQuery(Cat).filtered(`name = '${catName}'`)[0]; + const cat = useQuery( + Cat, + cats => { + return cats.filtered(`name = '${catName}'`); + }, + [catName], + )[0]; // Use the type check to handle your data. const catBirthDate = isString(cat.birthDate, 'birthDate', cat) ? cat.birthDate diff --git a/source/examples/generated/react-native/ts/quickstart-find-sort-filter.test.snippet.find-sort-filter.tsx b/source/examples/generated/react-native/ts/quickstart-find-sort-filter.test.snippet.find-sort-filter.tsx index 3b5e436a26..d2f18bf1b4 100644 --- a/source/examples/generated/react-native/ts/quickstart-find-sort-filter.test.snippet.find-sort-filter.tsx +++ b/source/examples/generated/react-native/ts/quickstart-find-sort-filter.test.snippet.find-sort-filter.tsx @@ -57,7 +57,13 @@ const FindSortFilterComponent = ({ letter: string, ) => { // Use [c] for case-insensitivity. - const filtered = profiles.filtered(`name ${filter}[c] "${letter}"`); + const filtered = useQuery( + Profile, + profiles => { + return profiles.filtered(`name ${filter}[c] "${letter}"`); + }, + [filter, letter], + ); setAllProfiles(filtered); }; diff --git a/source/examples/generated/react-native/ts/read.test.snippet.crud-read-filter-data.tsx b/source/examples/generated/react-native/ts/read.test.snippet.crud-read-filter-data.tsx index 7fab4af5aa..7785197400 100644 --- a/source/examples/generated/react-native/ts/read.test.snippet.crud-read-filter-data.tsx +++ b/source/examples/generated/react-native/ts/read.test.snippet.crud-read-filter-data.tsx @@ -1,14 +1,17 @@ const TaskList = () => { - // retrieve the set of Task objects - const tasks = useQuery(Task); - // filter for tasks with a high priority - const highPriorityTasks = tasks.filtered('priority >= $0', 4); + const highPriorityTasks = useQuery(Task, tasks => { + return tasks.filtered('priority >= $0', 4); + }); // filter for tasks that have just-started or short-running progress - const lowProgressTasks = tasks.filtered( - '$0 <= progressMinutes && progressMinutes < $1', 1, 10 - ); + const lowProgressTasks = useQuery(Task, tasks => { + return tasks.filtered( + '$0 <= progressMinutes && progressMinutes < $1', + 1, + 10, + ); + }); return ( <> diff --git a/source/examples/generated/react-native/ts/relationships-test.snippet.query-backlinks.tsx b/source/examples/generated/react-native/ts/relationships-test.snippet.query-backlinks.tsx index e32e6cf008..a0b1fec79a 100644 --- a/source/examples/generated/react-native/ts/relationships-test.snippet.query-backlinks.tsx +++ b/source/examples/generated/react-native/ts/relationships-test.snippet.query-backlinks.tsx @@ -1,12 +1,12 @@ + const PostsByYoungUsers = () => { - const posts = useQuery(Post); - const postsByYoungUsers = useMemo(() => { + const postsByYoungUsers = useQuery(Post, posts => { return posts.filtered( '@links.User.posts.birthdate >= 2000-01-01@00:00:00:0', ); - }, [posts]); + }); - if (!posts) return The post was not found.; + if (!postsByYoungUsers) return The post was not found.; return ( Posts By Young Users diff --git a/source/examples/generated/react-native/ts/sets-test.snippet.add-items-to-set.tsx b/source/examples/generated/react-native/ts/sets-test.snippet.add-items-to-set.tsx index f249a006f5..ee7d3be741 100644 --- a/source/examples/generated/react-native/ts/sets-test.snippet.add-items-to-set.tsx +++ b/source/examples/generated/react-native/ts/sets-test.snippet.add-items-to-set.tsx @@ -5,8 +5,12 @@ const AddInventoryToCharacter = ({ }) => { const realm = useRealm(); const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const addInventoryItem = () => { diff --git a/source/examples/generated/react-native/ts/sets-test.snippet.check-set-items-and-size.tsx b/source/examples/generated/react-native/ts/sets-test.snippet.check-set-items-and-size.tsx index 3cc573d1a3..d4cfbbb0b4 100644 --- a/source/examples/generated/react-native/ts/sets-test.snippet.check-set-items-and-size.tsx +++ b/source/examples/generated/react-native/ts/sets-test.snippet.check-set-items-and-size.tsx @@ -4,8 +4,12 @@ const QueryCharacterInventory = ({ characterName: string; }) => { const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const queryCharacterInventory = () => { diff --git a/source/examples/generated/react-native/ts/sets-test.snippet.remove-items-from-set.tsx b/source/examples/generated/react-native/ts/sets-test.snippet.remove-items-from-set.tsx index 83055a9fa3..679cdfadec 100644 --- a/source/examples/generated/react-native/ts/sets-test.snippet.remove-items-from-set.tsx +++ b/source/examples/generated/react-native/ts/sets-test.snippet.remove-items-from-set.tsx @@ -5,8 +5,12 @@ const RemoveInventoryFromCharacter = ({ }) => { const realm = useRealm(); const [inventoryItem, setInventoryItem] = useState(''); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const removeInventoryItem = () => { diff --git a/source/examples/generated/react-native/ts/sets-test.snippet.traverse-a-set.tsx b/source/examples/generated/react-native/ts/sets-test.snippet.traverse-a-set.tsx index 0548149104..f1a2d13b04 100644 --- a/source/examples/generated/react-native/ts/sets-test.snippet.traverse-a-set.tsx +++ b/source/examples/generated/react-native/ts/sets-test.snippet.traverse-a-set.tsx @@ -7,8 +7,12 @@ const TraverseCharacterInventory = ({ const [inventoryItem, setInventoryItem] = useState(''); const [inventory, setInventory] = useState([]); - const character = useQuery(Character).filtered( - `name = '${characterName}'`, + const character = useQuery( + Character, + characters => { + return characters.filtered(`name = '${characterName}'`); + }, + [characterName], )[0]; const addInventoryItem = () => { diff --git a/source/examples/generated/react-native/v12/FtsQuery.snippet.react-native-fts-query.tsx.rst b/source/examples/generated/react-native/v12/FtsQuery.snippet.react-native-fts-query.tsx.rst index 79889b7648..a26cd1c1c8 100644 --- a/source/examples/generated/react-native/v12/FtsQuery.snippet.react-native-fts-query.tsx.rst +++ b/source/examples/generated/react-native/v12/FtsQuery.snippet.react-native-fts-query.tsx.rst @@ -6,7 +6,11 @@ const books = useQuery(Book); // Filter for books with 'hunger' in the name - const booksWithHunger = books.filtered('name TEXT $0', 'hunger'); + const booksWithHunger = useQuery(Book, books => { + return books.filtered('name TEXT $0', 'hunger'); + }); // Filter for books with 'swan' but not 'lake' in the name - const booksWithSwanWithoutLake = books.filtered('name TEXT $0', 'swan -lake'); + const booksWithSwanWithoutLake = useQuery(Book, books => { + return books.filtered('name TEXT $0', 'swan -lake'); + });