Our Community Forum is full of helpful information and Anvil experts. For example, whoever wrote the reset_description() function never had to worry about caching! That’s an internal detail, handled by the Video class – just as it should be. When you build an API like this, things “just work”. If the client hadn’t passed the Video object to the server, then the update would have stayed secret. Remember, this only happens because the client has proven that it’s allowed to see these updates. So Anvil knows to transmit the update to the calling code, where it triggers the update handler and updates. When reset_description() calls set_video_description(), it also passes the capability. When we call reset_description(), we’re passing the whole Video object, including its capability – so Anvil’s serialisation machinery knows that we have access to this capability. description ) # prints "© 2000 Anvil Records" How it works call ( 'reset_description', my_video ) print ( my_video. You can also create them directly in Python code from byte strings or source URLs. This will cause it to show up in the Toolbox under Custom. Now tick Make this Form available as a component. You can also click on this button to open the ‘Use as component’ menu. ![]() Add these imports to your form from anvil.js.window import jQuery from anvil.js import getdomnode. Alternatively, you can select the MyWidget form and click on the Use as Custom Component button on the top-right corner of the Form Editor. Media Objects Media objects are created by Anvil APIs such as FileLoader components and the Google Drive API. Let’s start by importing jQuery and getdomnode at the top of our Anvil app’s form. Check the Quickstart to see some examples using them. ![]() description ) # prints "Charlie Bit My Finger" anvil. Files, Media and Binary Data All binary data (pictures, uploaded files, etc.) is represented in Anvil as Media objects. We update the Video class to store the video description in the description attribute, so it can easily be displayed in the UI: Let’s expand our YouTube editor example from last time, to cache some information about each video. The code at the other end can register a callback (using set_update_handler()), which will be called with any updates when the server call completes. These updates will only be transmitted to the client if the client supplied that Capability as part of this call. To solve this problem, Anvil allows you to transmit updates about a particular Capability scope, by calling send_update() on a Capability object. It lets you: Track changes that you’ve made to your code. This is the job of Anvil’s version control system. You want to cache that information as part of your object.īut what happens when some server-side code updates that object? You want to update that cache, otherwise your client side will see stale data.īut, sometimes the server-side code is updating something secret that we don’t want the client to know about! So we only sometimes want to transmit cache updates. As we write software, it’s good to keep track of the changes we’ve made, and previous versions. ![]() If you’re using portable objects to represent long-lived server-side resources, you probably don’t want to go back to the server every time you fetch a property from your object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |