Removed packer worker implementation

This commit is contained in:
squidfunk 2020-02-19 16:57:32 +01:00
parent 577ad4ccc4
commit 03010ddbcd
16 changed files with 8 additions and 305 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,6 @@
{
"assets/javascripts/bundle.js": "assets/javascripts/bundle.274c4c16.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.274c4c16.min.js.map",
"assets/javascripts/worker/packer.js": "assets/javascripts/worker/packer.c14659e8.min.js",
"assets/javascripts/worker/packer.js.map": "assets/javascripts/worker/packer.c14659e8.min.js.map",
"assets/javascripts/bundle.js": "assets/javascripts/bundle.7de51c1a.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.7de51c1a.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.926ffd9e.min.js",
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.926ffd9e.min.js.map",
"assets/stylesheets/app-palette.scss": "assets/stylesheets/app-palette.3f90c815.min.css",

View File

@ -190,7 +190,7 @@
{% endblock %}
</div>
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.274c4c16.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.7de51c1a.min.js' | url }}"></script>
<script id="__lang" type="application/json">
{%- set translations = {} -%}
{%- for key in [
@ -209,7 +209,7 @@
{%- endfor -%}
{{ translations | tojson }}
</script>
<script>app=initialize({base:"{{ base_url }}",worker:{search:"{{ 'assets/javascripts/worker/search.926ffd9e.min.js' | url }}",packer:"{{ 'assets/javascripts/worker/packer.c14659e8.min.js' | url }}"}})</script>
<script>app=initialize({base:"{{ base_url }}",worker:{search:"{{ 'assets/javascripts/worker/search.926ffd9e.min.js' | url }}"}})</script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -37,7 +37,6 @@
"escape-string-regexp": "^2.0.0",
"lunr": "^2.3.8",
"lunr-languages": "^1.4.0",
"lz-string": "^1.4.4",
"ramda": "^0.26.1",
"rxjs": "^6.5.3"
},

View File

@ -31,7 +31,6 @@ export interface Config {
base: string /* Base URL */
worker: {
search: string /* Search worker URL */
packer: string /* Packer worker URL */
}
}
@ -54,5 +53,4 @@ export function isConfig(config: any): config is Config {
&& typeof config.base === "string"
&& typeof config.worker === "object"
&& typeof config.worker.search === "string"
&& typeof config.worker.packer === "string"
}

View File

@ -20,5 +20,4 @@
* IN THE SOFTWARE.
*/
export * from "./packer"
export * from "./search"

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A RTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import { Subject } from "rxjs"
import { WorkerHandler, watchWorker } from "observables"
import { PackerMessage } from "../message"
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Setup packer web worker
*
* This function will create a web worker that helps in packing and unpacking
* strings using an LZ-based algorithm, namely `lz-string`. Its main purpose is
* to compress the search index before storing it in local storage, so it can
* be retrieved and imported to minimize the time necessary to setup search.
*
* @see https://bit.ly/2Q1ArhU - LZ-String documentation
*
* @param url - Worker url
*
* @return Worker handler
*/
export function setupPackerWorker(
url: string
): WorkerHandler<PackerMessage> {
const worker = new Worker(url)
/* Create communication channels */
const tx$ = new Subject<PackerMessage>()
const rx$ = watchWorker(worker, { tx$ })
/* Return worker handler */
return { tx$, rx$ }
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
export * from "./_"
export * from "./message"

View File

@ -1,99 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import {
compress,
compressToUTF16,
decompress,
decompressFromUTF16
} from "lz-string"
import { PackerMessage, PackerMessageType } from "../message"
/* ----------------------------------------------------------------------------
* Data
* ------------------------------------------------------------------------- */
/**
* Determine methods for packing and unpacking
*
* While all Webkit-based browsers can store invalid UTF-16 strings in local
* storage, other browsers may only store valid UTF-16 strings.
*
* @see https://bit.ly/2Q1ArhU - LZ-String documentation
*/
const isWebkit = navigator.userAgent.includes("AppleWebKit")
/* ------------------------------------------------------------------------- */
/**
* Method for packing
*/
const pack = isWebkit
? compress
: compressToUTF16
/**
* Method for unpacking
*/
const unpack = isWebkit
? decompress
: decompressFromUTF16
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Message handler
*
* @param message - Source message
*
* @return Target message
*/
export function handler(message: PackerMessage): PackerMessage {
switch (message.type) {
/* Pack an unpacked string */
case PackerMessageType.STRING:
return {
type: PackerMessageType.BINARY,
data: pack(message.data)
}
/* Unpack a packed string */
case PackerMessageType.BINARY:
return {
type: PackerMessageType.STRING,
data: unpack(message.data)
}
}
}
/* ----------------------------------------------------------------------------
* Worker
* ------------------------------------------------------------------------- */
self.addEventListener("message", ev => {
self.postMessage(handler(ev.data))
})

View File

@ -1,91 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/* ----------------------------------------------------------------------------
* Types
* ------------------------------------------------------------------------- */
/**
* Packer message type
*/
export const enum PackerMessageType {
STRING, /* String data */
BINARY /* Packed data */
}
/* ------------------------------------------------------------------------- */
/**
* A message containing an unpacked string
*/
export interface PackerStringMessage {
type: PackerMessageType.STRING /* Message type */
data: string /* Message data */
}
/**
* A message containing a packed string
*/
export interface PackerBinaryMessage {
type: PackerMessageType.BINARY /* Message type */
data: string /* Message data */
}
/* ------------------------------------------------------------------------- */
/**
* A message exchanged with the packer worker
*/
export type PackerMessage =
| PackerStringMessage
| PackerBinaryMessage
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Type guard for packer binary messages
*
* @param message - Packer worker message
*
* @return Test result
*/
export function isPackerBinaryMessage(
message: PackerMessage
): message is PackerBinaryMessage {
return message.type === PackerMessageType.BINARY
}
/**
* Type guard for packer string messages
*
* @param message - Packer worker message
*
* @return Test result
*/
export function isPackerStringMessage(
message: PackerMessage
): message is PackerStringMessage {
return message.type === PackerMessageType.STRING
}

View File

@ -399,8 +399,7 @@
app = initialize({
base: "{{ base_url }}",
worker: {
search: "{{ 'assets/javascripts/worker/search.js' | url }}",
packer: "{{ 'assets/javascripts/worker/packer.js' | url }}"
search: "{{ 'assets/javascripts/worker/search.js' | url }}"
}
});
</script>

View File

@ -287,21 +287,6 @@ export default (_env: never, args: Configuration): Configuration[] => {
hashDigestLength: 8,
libraryTarget: "var"
}
},
/* Packer worker */
{
...base,
entry: {
"assets/javascripts/worker/packer":
"src/assets/javascripts/workers/packer/main"
},
output: {
path: path.resolve(__dirname, "material"),
filename: `[name]${hash}.js`,
hashDigestLength: 8,
libraryTarget: "var"
}
}
]
}