Skip to content

Commit

Permalink
refactor: move global Q config to document links
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jun 21, 2021
1 parent b3f53f5 commit 3f2d725
Show file tree
Hide file tree
Showing 38 changed files with 207 additions and 545 deletions.
21 changes: 0 additions & 21 deletions docs/QRL.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,6 @@ The above says that the `/handle_click` can be found relative to `myApp:`. This

The above global configuration simply says that `myApp:/handle_click` should be translated to `http://myserver.com/app/handle_click`. Notice that all which is needed to configure the protocol is declaration of `Q` property on global namespace such as `window`.

### Server protocol configuration

Configuring protocol on the server serves the same purpose as on the client, but is a bit more complicated because a single server can serve multiple applications and therefore is contextual.

As a convention create a `CONFIG.ts` file in a directory which will control protocols in that directory and its subdirectories.

```typescript
import { setConfig } from './index.js';

setConfig({
baseURI: import.meta.url,
protocol: {
myApp: 'http://myserver.com/app',
},
});
```

The important part is the `baseURI` which gets set to the obsolete URL of this file (`import.meta.url` returns `file://path/to/CONFIG.js`.) This will tell Qwik to resolve all files which come from a `file://path/to/**` folder using this configuration.

It is important that you import the `CONFIG.ts` file someplace from the root of the application so that the protocols can get configured before they are used.

## File extension

When Qwik imports a QRL it always imports it with a `.js` extension.
Expand Down
14 changes: 0 additions & 14 deletions integration/hello_server/CONFIG.ts

This file was deleted.

1 change: 0 additions & 1 deletion integration/hello_server/server_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE
*/

import './CONFIG.js';
import { jsxFactory, jsxRender } from './qwik.js';
import { Greeter } from './Greeter.js';

Expand Down
18 changes: 0 additions & 18 deletions integration/todo/CONFIG.ts

This file was deleted.

8 changes: 4 additions & 4 deletions integration/todo/client.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<html>
<head>
<title>ToDo Application</title>
<script src="/qwikloader.min.js" type="module"></script>
<script>
var Q = { protocol: { ui: './ui', data: './data', base: './' } };
</script>
<script src="/qwikloader.js" type="module"></script>
<link rel="q.protocol.ui" href="./ui" />
<link rel="q.protocol.data" href="./data" />
<link rel="q.protocol.base" href="./" />
<link rel="stylesheet" href="./base.css" />
<link rel="stylesheet" href="./index.css" />
</head>
Expand Down
7 changes: 4 additions & 3 deletions integration/todo/server_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE
*/

import './CONFIG.js';
import { jsxFactory, jsxRender } from './qwik.js';
import { ToDoApp } from './ui/TodoApp.js';

Expand All @@ -22,8 +21,10 @@ export async function serverMain(document: Document) {
<html>
<head>
<title>ToDo Application</title>
<script src="/qwikloader.min.js" type="module" events="click;dblclick;keyup;blur"></script>
<script>{"var Q={protocol:{ui:'./ui',data:'./data',base:'./'}}"}</script>
<script src="/qwikloader.js" type="module" events="click;dblclick;keyup;blur"></script>
<link rel="q.protocol.ui" href="./ui" />
<link rel="q.protocol.data" href="./data" />
<link rel="q.protocol.base" href="./" />
<link rel="stylesheet" href="./base.css" />
<link rel="stylesheet" href="./index.css" />
</head>
Expand Down
11 changes: 1 addition & 10 deletions src/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,13 @@ ts_project(
["**/*.ts"],
exclude = [
"**/*.unit.ts",
"CONFIG.ts",
],
),
declaration = True,
tsconfig = "//:tsconfig",
# TODO: https://bazelbuild.github.io/rules_nodejs/TypeScript.html#ts_project-supports_workers
)

ts_project(
name = "CONFIG",
srcs = ["CONFIG.ts"],
declaration = True,
tsconfig = "//:tsconfig",
deps = [":core"],
)

ts_project(
name = "unit_lib",
srcs = glob([
Expand All @@ -44,9 +35,9 @@ ts_project(
declaration = True,
tsconfig = "//:tsconfig",
deps = [
":CONFIG",
":core",
"//src/core/testing",
"//src/core/testing:unit_lib",
"@npm//@types/chai",
"@npm//@types/mocha",
],
Expand Down
20 changes: 0 additions & 20 deletions src/core/CONFIG.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/core/component/component.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE
*/

import '../CONFIG.js';
import { expect } from 'chai';
import { ComponentFixture, GreeterComponent } from '../testing/component_fixture.js';
import { AttributeMarker } from '../util/markers.js';
Expand Down
3 changes: 0 additions & 3 deletions src/core/config/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions src/core/config/index.ts

This file was deleted.

161 changes: 0 additions & 161 deletions src/core/config/qGlobal.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/core/config/qGlobal.unit.ts

This file was deleted.

0 comments on commit 3f2d725

Please sign in to comment.