Is it possible listening to db changes in Dynamo db from React Native?
The goal is to update automatically a value in React Native when something changes in the DB.
Amplify supports it, but it is only possible if the origin of the change is done through the grapql api (from another user of your react native app), and not if the change in the db is is originated from somewere else (for example a lambda function). This is because in aws amplify it is aws AppSync that is pushing the change message.
If the origin of the change is from somewere else, you need to manually configure a lambda function and attach it as a trigger to dynamodb (this might be possible through the amplify cli, but I have never done it that way so I am not sure) and make the lambda function for example send a websocket/mqtt message to your app. But that is a lot of manually coding and configuring.
If the origin is from a user of your app, through the graphql api, amplify provides you with an out of the box subscription possibility. I use angular, and when use amplify I get a file called API.service.ts (not sure if it is the same for react native). In that file there would be an observable called for example OnCreateTodoListener.
You can use that that observable to subscribe to create events. Or similar for OnUpdateTodoListener etc.
The graphql query looks something like this (typescript version for angular):
OnUpdateTodoListener: Observable<
SubscriptionResponse<OnUpdateTodoSubscription>
> = API.graphql({
query:
`subscription OnUpdateTodo {
onUpdateTodo {
__typename
id
}
}`
}
) as Observable<SubscriptionResponse<OnUpdateTodoSubscription>>;
These listerers should already be availiable for you, unless you have manually configured your graphql schema model to not allow subscriptions.
Take a look at the docs for mor detailed information
Related
I'm using Nuxt 2.15 with target: "static" and hosting on a shared hosting "hostinger". I fetch the data from an external API using axios and Vuex state management and here comes the problem where the app doesn't load the new data it gets from the API.
How can I make the app rerenders its data and output the newly updated data it gets from fetching the API?
I assume you are using nuxtServerInit or asyncData for getting the data from API. This used with static mode means that data is get only during generation. Which is great for not too often updated content because it doesn't have to connect to server every time it's faster.
Depend on your needs you can:
Get data from API in mounted() hook this will get data from API every time the page is loaded BUT it also means that it could be loaded with some delay and it probably wouldn't be indexed by search engines
You can go with universal mode (https://nuxtjs.org/docs/configuration-glossary/configuration-mode/) and start your site on node.js server which will use up-to-date data from API each time user will open your site.
EDIT: as #kissu corrected me in comment this one is deprecated, please use this one: target:'server' instead of target:'static', which is default so you can just remove this line (https://nuxtjs.org/docs/configuration-glossary/configuration-target/ )
I know there is a specific instruction pre-written on metaplex package that allow us to update on-chain metadata of a NFT, but I couldn't find or figure out a way to update off-chain data through api call from either frontend or backend.
I believe this can be done through a service like AWS S3, but I am wondering if there is a better way to achieve this goal
Questions:
So, 1) I want to ask is there a better method to update off-chain data through AWS S3 bucket, and 2) If so, could you explain how? 3) If not, could you explain how can I update json file on S3 Bucket through api calls from my frontend or backend.
Thanks!
Off-chain metadata is not part of the Solana Network so there are not any function/command that allow you to change data inside a offchain object.
What are your options?
You can change the onchain pointer to the offchain link to another (Metadata account has an uri field inside the onchain data that you can change to any other uri using metaboss for example). This is the normal option if you are using an storage like Arweave, because arweave stored files are unmutables.
If you are using something like S3, the way to update the offchain data is creating a backend that allow you to interact with ur AWS storage and change the data that you want. This will affect the NFT that has the onchain pointer to that offchain file, so you dont have to run any onchain update, just need to create a backend system that allow you to interact with ur AWS files.
If you wish to have Dynamic Metadata you can check out Cardinal.io as Well. Link
Google sent me a reminder to migrate from Dialogflow API v1 to v2. I don't use Dialogflow. The skill is connected to custom Python code on our own servers. Our code gets JSON and returns JSON. Should I be concerned?
What you've described still could be using Dialogflow, since Actions using Dialogflow can also be written in Python and receive JSON.
Some things that might be indicators:
If you have an actions.json file, and deploy this when you update your Action, you are probably not using Dialogflow.
If the JSON you receive contains an attribute "result" or "originalRequest" (or both), then you're using Dialogflow's fulfillment webhook protocol.
If you're looking at inputs[0].intent to see what Intent was triggered, and the value either matches one in your actions.json or a string such as actions.intent.TEXT, then you're using the Actions SDK and not Dialogflow.
If you were looking at result.metadata.intentName to get the name of the Intent, then you're using Dialogflow.
If you are using Dialogflow, you need to move to v2, which will require some changes in the names of several of the JSON fields. https://dialogflow.com/docs/reference/v1-v2-migration-guide-fulfillment#webhook_request_and_response_json (and sections further down on the page) provide information on the changes and what you'll need to do.
Yes! you should be concerned, I have faced the same issue as JSON has been changed for somethings already.
I have a ReactNative app that is working with some constants,
export const BEARER_TOKEN = 'eyJhbGciOiJIU***'
The app works fine until I need to update the token so with a new version distributed by appcenter,
If I just update the app, it keeps the old token
but
If I delete and install a new version, the new token is used
So, how can I make sure that the new token gets loaded? like if the app starts reload constants?
Thanks.
I suggest using Asyncstorage and Redux state in order to maintain your Bearer_Token.
For instance, assume using the Facebook app.
You are logging in for the very first time. Capture and store your Bearer_token in Asyncstorage and also maintain in the redux state.
Next time when you kill the app and open again. Load the Bearer_Token from Asyncstorage.
Your Bearer_Token will be set dynamically.
You can't, with this approach. This is the nature of javascript, it loads everything initially and even if you change it by putting the variable in object. It is a bad practice.
The better approach is to use redux or context api,
I see you want to use BEARER_TOKEN, for user authentication probably.
So you can have a state, authUser inside your redux and it will keep track of the token in your entire app. This approach is very useful when you want the user to logout if any change in authToken.
https://redux.js.org/
For a simple version, you can use context api from react.
now the third option, If you really really really want to not use these approaches.
You can just usewindow.token = 'sdfasdf';
then whenever you want to change it, just use window.token = 'soemthing else'from other files.
I am developing a front end mobile application with react-native and redux implementation. I had successfully pulled all the necessary real APIs. Now I want to create a function that can update the student's info. Fyi, I'm developing a student information system, so there's info like address and email that need to be updated if changes occur. I don't know how to do it, I heard people uses "lodash" which I dunno what it is for. And how do I save the updated changes?
To update state of redux, it is good idea to use helper like react-addons-update or immutability-helper. update() provides simple syntactic pattern to make writing state update code easier. Eg:
import update from 'immutability-helper';
function handleUpdateMydata(state, action){
return update(state,{
myData:{
$set:action.payload
}
})
}
To ensure your state is permanent store, you may use redux-persist
lodash is a library that is used for dealing with the arrays and objects. if you wanna know more about its content see the documentation here
Documentation
Now coming on to your real problem,since you are using redux I think you should create an action that would update your student details in the database