Request new features or modifications


Post by vadim_g »

Hi guys,

The AjaxStore ignores options.parseJSON: false, when transformLoadedData(response.parsedJson) is called. We would like to parse YML instead of JSON. Could you please handle also this case so the response is passed in transformLoadedData when parseJSON is false ?

Thanks.
Vadim


Post by marcio »

Hey Vadim,

Thanks for reaching out.

The AjaxStore is designed to work with JSON data, and currently, it does not support parsing YML directly. The transformLoadedData function is called with the parsed JSON data, and there isn't a built-in option to bypass JSON parsing.

To handle YML, you might consider intercepting the fetch response before it reaches the store and converting it to JSON format. You can use a custom fetch function or middleware to achieve this.

Here's a basic example of how you might intercept and transform the response:

const store = new AjaxStore({
    readUrl: 'your-url',
    fetchOptions: {
        // Custom fetch function
        fetch: async (url, options) => {
            const response = await fetch(url, options);
            const ymlData = await response.text();
            const jsonData = yourYmlToJsonFunction(ymlData); // Convert YML to JSON
            return new Response(JSON.stringify(jsonData), {
                headers: { 'Content-Type': 'application/json' }
            });
        }
    }
});

This way, you can transform the YML data into JSON before it is processed by the store.

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by vadim_g »

Hi Marcio,

Thank you for the workaround.

Still I think you need to finish the code around options.parseJSON: false, because otherwise it is an useless parameter. And the only change required is just on this line:

data        = me.transformLoadedData ? me.transformLoadedData(response.parsedJson) : response.parsedJson,

to:

data        = me.transformLoadedData ? me.transformLoadedData((options.parseJson ? response.parsedJson : response)) : response.parsedJson,

And this change will lead to less final code than the workaround above.


Post by marcio »

Hey Vadim,

Thanks for the suggestion. I'll let the dev team know about this and see if they can create a ticket to implement that.

Where do you see the parseJSON config? I don't see at https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by vadim_g »

It is in AjaxStore and AjaxHelper source code.


Post by vadim_g »

Your workaround does not seem to work, the AjaxStore.sendLoadRequest is still using the default fetch


Post by alex.l »

Hi vadim,

It is in AjaxStore and AjaxHelper source code.

Please never rely on private code, only use documented public API.

Your workaround does not seem to work, the AjaxStore.sendLoadRequest is still using the default fetch

Please show your code. In Marcio's demo code he created an instance with overloaded method. Did you call instance's method? Your code looks like AjaxStore is not an instance.

All the best,
Alex Lazarev

How to ask for help? Please read our Support Policy


Post by vadim_g »

Hi Alex

Please never rely on private code, only use documented public API.

Due to some missing features in Bryntum, we've had to dive into the code, apply overrides, and tailor it to our needs — confidently and with tests. So no worries, unless you want help us adding those things ;)

Please show your code. In Marcio's demo code he created an instance with overloaded method. Did you call instance's method? Your code looks like AjaxStore is not an instance.

It works as you've shown, but not in a store class like here https://codepen.io/Vadim-Popa/pen/bNVWLQa . Also the only "your code" I've shared in this thread, is from the source code of the AjaxStore


Post by alex.l »

The reason why we do not recommend to use private API is because we rename/remove/change private logic/methods without any notification, expected and actual behaviour of methods might be not fit your expectations. Another problem you will face - problems when upgrade versions. We release every few weeks and do not support old versions, all fixes are always only in last release.

You use sendLoadRequest as static method, but it's not static. Please make sure you see difference via class and instance.
If you need, you can add static method and use it, or override base class. https://bryntum.com/products/grid/docs/api/Core/mixin/Override

All the best,
Alex Lazarev

How to ask for help? Please read our Support Policy


Post by vadim_g »

We understand that risk, and for that we have tests. Those will catch any issues quickly. Also we are running diffs between the versions to understand what has changed.

Have you checked the codepen I shared, from API point of view or use case, it's a valid example. Please let me know how can I have a store class that can parse an YML (accept our parser, or in Sencha world a yml reader) that can be instantied by related widgets (combo).....of course we can find workarounds for this...but from API point of view it seems that Bryntum does not support this by default, hence is the Feature request.


Post Reply