Configs

Config example

I will explain every config bellow the example.

const app = new App({
    components: components, 
    helper: function() {
        // The Helpers of your choice will be passed to the controllers, views and components
        return {
            yourHelper1: {},
            yourHelper2: {}
        };
    },
    ready: function(builder, observer) {
        //const inst = this; // Stratox main instance
    },
    request: { // Enable Ajax
        dataType: "json",
        url: "https://example.se/backend-location/",
        path: '/api',
        startPath: "home",
        config: {
            headers: {
                'Accept': 'application/json'
            }
        },
        get: function(searchParams) {
            searchParams.append("param", 1);
            return searchParams;
        },
        post: function(object) {
            object.param = 1;
            return object;
        }
    }
});

components

Components are loaded by default in the main.js file. You can customize the component file "./src/templates/components.js" or create a new one. This file contains elements such as form fields and is utilized by the form builder. Note that the form builder will not function without the components. However, if your application does not utilize any forms, you can manage without it. In such cases, you can remove components from the configuration entirely, thereby reducing the size of your application.

helper

The helper config allows you to pass all third-party library functions to your routes, controllers, views, and components. This enables you to easily utilize these functions by initializing them in one central location and then distributing them throughout the app.

The helper config accepts any data type, but it's highly recommended to structure it as a function that returns an object containing the expected libraries, like bellow.

helper: function() {
    return {
        yourHelper1: {},
        yourHelper2: {}
    };
}

ready

This will be triggered once the main Startox view has finished loading.

request (ajax)

Read more about ajax in the Ajax Integration section.

  • url: The URL to your site/API location to access via Ajax.

  • dataType: Set expected response data type json, xml or text. Json response will be converted to object, xml to DOMParser and text will be text. (default: json)

  • path: Extends the URL with a URI path. (optional)

  • startPath: Adds a default start path if the URI path is empty. (optional)

  • config: Supplies the fetch request with options. You can read more about these options here. (optional)

  • get: Passes custom or modifies a GET parameter for the controller result. (optional)

  • post: Passes custom or modifies a POST parameter for the controller result. (optional)

Last updated