美文网首页
react-native本地数据库realm

react-native本地数据库realm

作者: 朱传武 | 来源:发表于2021-11-03 07:38 被阅读0次

1、how local cart implemented
Because the ShoppingCart part needs to store information locally, this is now done with the local database Realm,
This is its docment https://docs.mongodb.com/realm/sdk/react-native/

image.png
This is the database structure, which you can find under the db folder under the project
2、local cart refresh - checking product avaialbility
Since we store the product information locally, we need to check whether the local product is still available when the server inventory and whether it is on the shelves are changed
The following method is called when we open the shopping cart page
const [queryAvailble, { data: availbleList }] = useLazyQuery(
    IsListingAvailable,
    {
      variables: { listings: isAvailableList },
    }
  );
  useEffect(() => {
    if (isAvailableList.length > 0) {
      queryAvailble();
    }
  }, [isAvailableList, queryAvailble]);

3、guest user and register buyer id and delivery address id
You can get buyerid directly by using global.buyerId, no matter a registerd buyer or a guest user
You can get delivery address id from apollo cache

 const {
    data: { localCartVar },
  } = useQuery(GET_LOCAL_CART);

then use localCartVar.deliverAddress
4、prepare list of data to send to back end for oder creation
you must get local shoppingcart info then call the checkout-related api

相关文章

网友评论

      本文标题:react-native本地数据库realm

      本文链接:https://www.haomeiwen.com/subject/afsqzltx.html