Skip to content

Implement use_location #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions docs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from idom.core.types import ComponentConstructor
from idom.server.sanic import Options, configure, use_request

from .examples import load_examples
from .examples import get_normalized_example_name, load_examples


HERE = Path(__file__).parent
Expand All @@ -26,10 +26,7 @@ def run():
configure(
app,
Example(),
Options(
redirect_root=False,
url_prefix=IDOM_MODEL_SERVER_URL_PREFIX,
),
Options(url_prefix=IDOM_MODEL_SERVER_URL_PREFIX),
)

app.run(
Expand All @@ -42,7 +39,8 @@ def run():

@component
def Example():
view_id = use_request().get_args().get("view_id")
raw_view_id = use_request().get_args().get("view_id")
view_id = get_normalized_example_name(raw_view_id)
return _get_examples()[view_id]()


Expand Down
2 changes: 1 addition & 1 deletion docs/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _get_root_example_path_by_name(name: str, relative_to: str | Path | None) ->
rel_path = rel_path.parent if rel_path.is_file() else rel_path
else:
rel_path = SOURCE_DIR
return rel_path.joinpath(*name.split("/"))
return rel_path.joinpath(*name.split("/")).resolve()


class _PrintBuffer:
Expand Down
29 changes: 28 additions & 1 deletion docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,34 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
Unreleased
----------

Nothing yet...
Added:

- Implement ``use_location()`` hook - :pull:`721`

Navigating to any route below the root of the application will be reflected in the
``location.pathname``. This operates in concert with how IDOM's configured routes have
changed. This will ultimately work towards resolving :issue:`569`.

Changed:

- The routes IDOM configures on apps have changed - :pull:`721`

.. code-block:: text

prefix/_api/modules/* web modules
prefix/_api/stream websocket endpoint
prefix/* client react app

This means that IDOM's client app is available at any route below the configured
``url_prefix`` besides ``prefix/_api``. The ``_api`` route will likely remain a route
which is reserved by IDOM. The route navigated to below the ``prefix`` will be shown
in ``use_location``.

- IDOM's client now uses Preact instead of React - :pull:`721`

Removed:

- ``redirect_root`` server option - :pull:`721`


0.38.0-a1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,20 @@ <h1>This is an Example App</h1>
<p>Just below is an embedded IDOM view...</p>
<div id="idom-app" />
<script type="module">
import { mountLayoutWithWebSocket } from "https://esm.sh/[email protected]";
import {
mountWithLayoutServer,
LayoutServerInfo,
} from "https://esm.sh/[email protected]";

// get the correct web socket protocol
let wsURL;
if (window.location.protocol === "https:") {
wsURL = "wss:";
} else {
wsURL = "ws:";
}
wsURL += "//" + window.location.host;
const serverInfo = new LayoutServerInfo({
host: document.location.hostname,
port: document.location.port,
path: "_idom",
query: queryParams.user.toString(),
secure: document.location.protocol == "https:",
});

// append path to the web socket
wsURL += "/_idom/stream";

// only needed for views that use web modules
const loadImportSource = (source, sourceType) =>
sourceType == "NAME"
? import("_idom/_modules/" + source)
: import(source);

mountLayoutWithWebSocket(
document.getElementById("idom-app"),
wsURL,
loadImportSource
);
mountLayoutWithWebSocket(document.getElementById("idom-app"), serverInfo);
</script>
</body>
</html>
12 changes: 4 additions & 8 deletions docs/source/guides/getting-started/running-idom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,15 @@ Server Configuration Options
----------------------------

IDOM's various server implementations come with ``Options`` that can be passed to their
respective ``configure()`` functions. Those which are common amongst the options are:

- ``url_prefix`` - prefix all routes configured by IDOM
- ``redirect_root`` - whether to redirect the root of the application to the IDOM view
- ``serve_static_files`` - whether to server IDOM's static files from it's default route

You'd then pass these options to ``configure()`` in the following way:
respective ``configure()`` functions in the following way:

.. code-block::

from idom.server.<implementation> import configure, Options

configure(app, MyComponent, Options(...))

To learn more read the description for your chosen server implementation:
To learn more read about the options for your chosen server ``<implementation>``:

- :class:`idom.server.fastapi.Options`
- :class:`idom.server.flask.Options`
Expand Down
3 changes: 3 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,8 @@ def get_idom_script_env() -> dict[str, str]:
return {
"PYTHONPATH": os.getcwd(),
"IDOM_DEBUG_MODE": os.environ.get("IDOM_DEBUG_MODE", "1"),
"IDOM_TESTING_DEFAULT_TIMEOUT": os.environ.get(
"IDOM_TESTING_DEFAULT_TIMEOUT", "6.0"
),
"IDOM_CHECK_VDOM_SPEC": os.environ.get("IDOM_CHECK_VDOM_SPEC", "0"),
}
4 changes: 2 additions & 2 deletions requirements/pkg-deps.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
typing-extensions >=3.10
mypy-extensions >=0.4.3
anyio >=3.0
anyio >=3
jsonpatch >=1.32
fastjsonschema >=2.14.5
requests >=2.0
requests >=2
colorlog >=6
4 changes: 2 additions & 2 deletions requirements/pkg-extras.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ fastapi >=0.63.0
uvicorn[standard] >=0.13.4

# extra=flask
flask<2.0
flask
markupsafe<2.1
flask-cors
flask-sockets
flask-sock

# extra=tornado
tornado
Expand Down
Loading