U4-2764 - assetsService doense always call "then"

Created by Markus Johansson 01 Sep 2013, 15:06:44 Updated by Per Ploug 16 Sep 2013, 13:11:37

I was watching Pers presentation on how to build property editors and so on for Umbraco 7.

When I was working on a tagging-data type I needed to load some js/css-files. So I used the approach that Per was showing during the demos:

assetsService.load(["files"]).then(function () { // Do my stuff in here });

The first time the page loads this works great and the function that I pass as the "then"-callback gets called. But if I for example load another node in the tree and then go back to this node again - since the files has already been loaded the "then"-funciton dosent get called.

I'm not sure if this is a bug? Per was recommending this approach over loading the js-files in the manifest file like this:

javascript: [ '~/myfile.js' ]

So if using the assetsSerivce is the way to go we would probably have to insure that the "then"-callback gets called when the files have already been loaded as well.

This problem should be present in the GoogleMaps data type as well since it loads the api like this:

assetsService.loadJs('http://www.google.com/jsapi') .then(function(){ google.load("maps", "3", { callback: initMap, other_params: "sensor=false" }); });

Comments

Per Ploug 16 Sep 2013, 13:11:37

the assetsService.load should only be used to load js files, because if you try to load a .css file as part of a collection, this will choke the callback, because browser cant actually tell when a css file is done loading.

So load the css file outside of this collection, like described in this tutorial: http://umbraco.github.io/Belle/#/tutorials/CreatingAPropertyEditor


Priority: Normal

Type: Bug

State: Fixed

Assignee: Per Ploug

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.0.0

Due in version:

Sprint:

Story Points:

Cycle: