Question

I'm currently using the latest version of breezejs (1.4.2), with requirejs and knockout. I have the following require config...

require.config({
paths:
{
    "jquery": "../Scripts/jquery-1.10.2.min", //using jquery 1.x for older browsers
    "bootstrap": "../Scripts/bootstrap.min",
    "knockout": "../Scripts/knockout-2.3.0",
    "knockoutMapping": "../Scripts/knockout.mapping-latest",
    "toastr": "../Scripts/toastr.min",
    "Q": "../Scripts/Q.min",
    "es5-shim": "../Scripts/es5-shim.min",
    "es5-polyfill": "../Scripts/es5-polyfill",
    "breeze": "../Scripts/breeze.min",
    "kendo": "../Scripts/kendo/2013.2.716/kendo.web.min",
    "knockoutKendo": "../Scripts/knockout-kendo.min",
    "globalize": "../Scripts/globalize/globalize",
    "globalize-au": "../Scripts/globalize/cultures/globalize.culture.en-AU"
},
shim:
{
    "jquery": { exports: "$" },
    "knockout": { deps: ["jquery"] },
    "Q": { deps: ["jquery", "knockout"] },
    "breeze": { deps: ["knockout", "jquery", "Q", "es5-shim", "es5-polyfill"] },
    "globalize-au": { deps: ["globalize"] },
    "bootstrap": { exports: "Bootstrap", deps: ["jquery"] },
    "kendo": { deps: ["jquery"] },
    "knockoutKendo": { deps: ["knockout", "kendo"] },
    "knockoutMapping": { deps: ["knockout"] }
}
});

Looking at the network traffic, breeze.min.js is loaded after all the listed dependencies above but I still get regular JSON objects returned by breeze queries and not knockout observable properties, as I would expect.

If I add the knockout script outside of requirejs, using standard script tags before the breeze script, then everything works. So, this does suggest an issue with dependencies and loading order preferences that I can't work out.

Here is a sample query that I am using to return the breeze entities. Note, that all my current breeze queries return entities with non-observable properties:

    // Look for the log in manager"s cache first
    // Fetch from the database if not found in the cache
    return manager
        .fetchEntityByKey("SqlLog", sqlLogId, true)
        .then(function (data)
        {
            log("Retrieved [SQL DETAILS] from remote data source", data, true);

            // using entity values here as breeze not returning observables.
            sqlText(data.entity.SqlText);
            parameters(data.entity.Parameters);
            exceptionMessage(data.entity.ExceptionMessage);
        })
        .fail(queryFailed);
Was it helpful?

Solution

Got hit with that one myself. The quick answer is breeze insists on looking only for "ko", so you can use that in your config instead.

Technical reason is that breeze explicitly looks for "ko". To find all the breeze requires search for 'requireLib' (not whole word) in the source.

Breeze always looks for global first, and since knockout's global is 'ko' that's what breeze searches for.

So when loading knockout outside of RequireJS, it is not timing but rather the "ko" var name availability that is fixing your problem.

See more detail in my related answer Difference between "Q" and "q" in angularjs and requirejs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top