Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

Breeze js without Q library for knockoutjs ? #68

Open rangarks opened 2 years ago

rangarks commented 2 years ago

Hi,

I am working on integrating some custom components written in blazor with an old .net mvc knockoutjs application. We are using breeze for Odata calls to our api. Breeze uses Q library to resolve promises and due to which traditional JS promises are having some sort of side effects due to which, "instance of Promise" always evaluates to false, even if the variable is a promise.

I am curious, to know if there's a way to implement breeze without using the Q library for .mvc Knockout applications !

Any suggestions are greatly appreciated

marcelgood commented 2 years ago

The latest version of breeze-client no longer uses Q. We've rewritten Breeze in TypeScript and are using ES6 promises now. I would recommend you upgrade to the latest version.

However, if you don't want to do it at this point, then yes you can replace Q with your own promise service using whatever promise implementation you like.

You can find an example in our old Angular bridge.

Here's the ES6 promise adapter: https://github.com/Breeze/breeze.bridge.angular/blob/master/src/common.ts

and then you just have to plug it in with config.setQ as shown here on line 15: https://github.com/Breeze/breeze.bridge.angular/blob/master/src/module.ts#L15

rangarks commented 2 years ago

@marcelgood - Thank you so much for responding, I was looking to update my breeze to latest version. I am using knockout js so previously app was directly referencing the scripts directly. Now to update I am following this guide here - https://github.com/Breeze/breeze-client/blob/master/UPGRADE.md

After directly referencing the files in my layout.cshtml, is this a right way to do ? Mine is an old .net mvc knockout application.

marcelgood commented 2 years ago

Yes, that's pretty much the way to go if you modernize your JavaScript or upgrade to TypeScript. You can also still reference the UMD scripts directly as shown at the end. We haven't used knockout in a long long time, and it's no longer the default, so you'll have to register the ModelLibraryKnockoutAdapter instead of the ModelLibraryBackingStoreAdapter used in the upgrade guide.