Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tolyo/server-page-component

Web Component for partials
https://github.com/tolyo/server-page-component

Last synced: 4 days ago
JSON representation

Web Component for partials

Awesome Lists containing this project

README

        

# Web Component for partials

Partial is a fragment of a web-page, loaded separately from the main content. This Web Component simplifies their use. It is based on Open Web Components defaults and recommendations.

## Install

```bash
$ npm i server-page-component

```

or

```html

```

## Usage

If using module imports:

```js
import 'server-page-component';
```

Then:

```html
# anywhere in your html

```

This will initiate an AJAX request to the address, specified in the `url` attribute, replacing the content of the component with received response. Modifying the `url` attribute will trigger a new request. If the `id` attribute is present, the component will use `window.document` as an event listener on `partial:#{id}` namespace. This allows partial content updates to be triggered from any part of your application.

## Example

```html

document.dispatchEvent(new Event("partial:SPY"))

```

Or use the helper `triggerServerPage`:

```js

import { triggerServerPage } from 'server-page-component';

triggerServerPage('SPY');

```

For updates from DOM without changing `url` attribute, a `latch` attribute
can be set to any value and the component will react to any changes to it. Example:

```html

```

Or wire it with a framework of choice:

```html






```