[Done] Make dependency's own assets available to the dependency

adding this as a feature request - would be useful.

Mostly for dependencies that use a little bit of javascript or css or roles.

Currently with dependencies where I want to inject some global css/javascript I would end up writing it directly in the native libraries of the dependency. This isn’t particularly clean… and not editable in an external ide.

Alternatively for every app that used the dependency I could include all the css/javascript/roles with the work around in the above post - but that’s convoluted so there must be a better way.

It would be nicer if there was a way that a dependency could have access to its own roles/assets.
It would clean up the code and make maintaining dependencies easier imo.

4 Likes

Hi @stucork,

Yes this sounds like a great addition - I’ve added it to our list :slight_smile:

1 Like

Ouch. Just been bitten by this one too.

A single role in a dependency with one line of css!

Yeap - when it comes to dependencies - i’ve often ended up moving js/css into the native libraries to account for this issue.

More recently, i’ve taken to adding some js/css features in python within the dependency and adding them dynamically. This way it can all be contained within a single python module.

from anvil.js.window import document
sheet = document.createElement('style')
sheet.innerHTML = """
div {
    border: 2px solid black; 
    background-color: blue;
}
""" 
document.body.appendChild(sheet)
1 Like

Nice! I was thinking of using custom HTML templates next to see what happened, but that is probably quicker and easier.

I’ve added a module into my extras library to handle injection as per the excellent suggestion from @stucork .

Now all I need some way to do the same for roles…

1 Like

This has now been implemented.

As an example, if your app depends on anvil-extras, you could add this line to your native libraries, which will adjust the default spinner colour to match your theme :wink:

<!-- adjust color as required -->
<script src="_/theme/loading-spinner.js" color="#E91E63"></script>
5 Likes