In this post, we’ll cover general practices for developing applications on the JourneyApps platform. If you have any of your own and would like to share it with our community, please comment on this post.
- Start with your data model definitions and iterate fast. The best way to achieve this would be to have the app open whilst you write code so you can see your change in real-time.
- Don’t be afraid to change the app. The JourneyApps rapid development paradigm makes it easy to change your app based on user feedback.
- Familiarize yourself with the performance suggestions as outlined in this article.
- Limit queries in XML functions as these functions execute on each digest cycle. For more information on this topic, please see the $: functions and the digest cycle section of the Improving App Performance article.
- Cache data as long as it will scale appropriately, i.e., store commonly executed query results as variables in your views.
.include()when working with related objects on your queries and arrays as it improves the performance of the look-ups. Please see the Include related objects in a query section of the Querying DB Objects documentation.
- When setting relationships to a parent object you could use the
object.parent_id = existingParent.idinstead of
object.parent(existingParent)function if the parent is nested as this removes an additional network request.
- It’s important to understand the difference between using
query:objectwhen bound to the query attribute of components (on an object-table, for example). Please make sure you familiarize yourself with the difference between the two by reading the Guidelines for choosing between array and query in this article of the official documentation.
- Using the
.forEach()function on query results yields unexpected results due to the asynchronous nature of the function. Note, this does not apply to query results that have been cast to an array via the
- When working with larger or distributed teams, make sure to leave comments in your code as this reduces the effort it takes to share context with team members.
- Avoid excessive
console.logstatements in your code in a production environment. This will consume valuable memory on devices.
- When defining Webhooks on data models which are of type update, add a value that must be present on a field before the CloudCode task is invoked. This allows you to avoid writing code to check if certain values are set before data can be processed. In addition to this, it will also allow you a mechanism to avoid the webhook retrying/retriggering itself in an infinite loop. For more information on how to configure conditional values on Webhooks in JourneyApps, please see the Conditions and Embedded Fields section of this article.
- When developing CloudCode tasks that need to process large amounts of data, make sure to add functionality that caters to limiting the number of objects a single task instance can process and also add in the ability to enqueue a new instance of the task to continue with the process once these limits are reached. Familiarize yourself with the limits of CloudCode by reviewing the Limits section of this article. The easiest limits to run into will be the total runtime limit and the memory usage limit. This post shows the built-in mechanisms for catching and handling this before it is a problem.
- Strongly consider importing error monitoring solutions into your CloudCode tasks in the event that the CloudCode tasks error. This will allow you to catch errors and exceptions in your code and report these errors for responsive actions before users notice anything. A good example of this would be rollbar. But there is a wide variety of services that offer the same functionality. Here is a list of other such services.
- Implement shared functionality using the shared CloudCode template.
multiple-choicefield types for static field options (options that will not change over time). If you expect the options to change rather use separate models to define the options and refer to them using relationships by setting
has-manyjoin models. If your
multiple-choiceoptions need to change you will most likely require data migrations to ensure historical data accuracy.
Familiarize yourself with app indexes and add them to your data models. This significantly improves the performance of your application queries. For more details on how to configure indexes, please see this article in our documentation.
Always include conditions to your sync rules. Keep in mind that sync rules need to be reprocessed when updates to the rules are deployed to your application. The time it takes to reprocess these rules is dependent on the amount of data in your application database, the number of recent changes to your data, and the number of recent deletes, so make sure to define the rules early on.
If changes are made to your sync rules, always check the sync diagnostics page to see how long the reprocessing of the will take. To find the Sync Diagnostics page, open the backend data browser for a particular instance, select the dropdown arrow (top right), elevate permissions if needed (this will refresh the page, meaning you’ll need to open the dropdown again), and then select the “Sync Diagnostics” option from the dropdown list.
Try to synchronize master data between environments when developing. This helps when debugging production code, without having to enroll a device in your production backend. The easiest way to accomplish this is through the use of the import/export CSV functionality on the backend instances.
Consider adding the following fields to all your models and populating them throughout. This will make it easier to find, audit and debug your data.
A Datetime field of when the data was deleted
A Datetime field of when the data was created
A belongs-to relationship between the object and the user who deleted the data
A belongs-to relationship between the object and the user who created the data