Skip to content

Commit

Permalink
Getting ready for 0.1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
emilhe committed Nov 8, 2021
1 parent aaa9044 commit 142beb2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [0.1.23] - 2021-08-11

### Change

- Changed loading of js chunks so that a chunk is only loaded when actually needed.

## [0.1.22] - 2021-08-11

### Added
Expand Down
106 changes: 59 additions & 47 deletions dash_leaflet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import json

import dash as _dash
# from . import assets # noqa

# noinspection PyUnresolvedReferences
from ._imports_ import *
from ._imports_ import __all__

if not hasattr(_dash, 'development'):
if not hasattr(_dash, '__plotly_dash') and not hasattr(_dash, 'development'):
print('Dash was not successfully imported. '
'Make sure you don\'t have a file '
'named \n"dash.py" in your current directory.', file=_sys.stderr)
Expand All @@ -29,50 +28,63 @@

_this_module = _sys.modules[__name__]

async_resources = ["markerClusterGroup", "editControl", "geoTiffOverlay", "locateControl", "measureControl",
"minichart", "null"]

_js_dist = []

_js_dist.extend(
[
{
"relative_package_path": "async-{}.js".format(async_resource),
"external_url": (
"https://unpkg.com/{0}@{2}"
"/{1}/async-{3}.js"
).format(package_name, __name__, __version__, async_resource),
"namespace": package_name,
"async": True,
}
for async_resource in async_resources
]
)

# TODO: Figure out if unpkg link works
_js_dist.extend(
[
{
"relative_package_path": "async-{}.js.map".format(async_resource),
"external_url": (
"https://unpkg.com/{0}@{2}"
"/{1}/async-{3}.js.map"
).format(package_name, __name__, __version__, async_resource),
"namespace": package_name,
"dynamic": True,
}
for async_resource in async_resources
]
)

_js_dist.extend(
[
{
'relative_package_path': 'dash_leaflet.min.js',
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js'.format(
package_name, __name__, __version__),
'namespace': package_name
},
{
'relative_package_path': 'dash_leaflet.min.js.map',
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js.map'.format(
package_name, __name__, __version__),
'namespace': package_name,
'dynamic': True
}
]
)

_css_dist = []
_js_dist = [
{
'relative_package_path': 'dash_leaflet.min.js',
'namespace': package_name
},
{
'relative_package_path': 'dash_leaflet.min.js.map',
'namespace': package_name,
'dynamic': True
}
]

# Prepare per-chunk js imports.
_chunk_map = {
"MarkerClusterGroup": ["markerClusterGroup"],
"EditControl": ["editControl"],
"GeoTiffOverlay": ["geoTiffOverlay"],
"LocateControl": ["locateControl"],
"MeasureControl": ["measureControl"],
"Minichart": ["minichart"],
}
_chunk_js_dist_map = {}
for _component in _chunk_map:
_chunk_js_dist_map[_component] = []
for entry in _chunk_map[_component]:
_chunk_js_dist_map[_component] += [
{
'relative_package_path': f'async-{entry}.js',
'namespace': package_name
},
{
'relative_package_path': f'async-{entry}.js.map',
'namespace': package_name,
'dynamic': True
}
]

# Add chunks to respective components so that they only load when the component is imported.
for _component in __all__:
_component_js_dist = _js_dist if _component not in _chunk_map else _js_dist + _chunk_js_dist_map[_component]
setattr(locals()[_component], '_js_dist', _component_js_dist)
setattr(locals()[_component], '_css_dist', _css_dist)

# Update _js_dist to hold ALL chunks to ensure Dash can load them.
for _component in _chunk_js_dist_map:
_js_dist += _chunk_js_dist_map[_component]

for _component in __all__:
setattr(locals()[_component], '_js_dist', _js_dist)
setattr(locals()[_component], '_css_dist', _css_dist)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "git://github.com/thedirtyfew/dash-leaflet.git"
},
"version": "0.1.22",
"version": "0.1.23",
"description": "Leaflet component for Dash",
"main": "build/index.js",
"scripts": {
Expand Down

0 comments on commit 142beb2

Please sign in to comment.