Coder Social home page Coder Social logo

spx's Introduction


Single Page XHR - The essential enhancement for static SSR powered web applications. SPX is a lightening fast, lightweight (15kb gzip) over the wire (push~state) solution that employs an incremental (snapshot) morphing tactic with DOM driven component capabilities integrated at the core.

Documentation

Documentation lives on spx.js.org

Features

  • Simple and painless drop-in integration.
  • Supports components extendability.
  • Pre-fetching capabilities using hover, intersection or proximity observers.
  • Snapshot caching engine and per-page state control.
  • Powerful pub/sub event driven lifecycle triggers.
  • Gracefully handles script and style asset evaluation.
  • Attribute driven programmatic control.

Installation

PNPM
pnpm add spx
YARN
yarn add spx
NPM
npm install spx --save
CDN
https://unpkg.com/spx

Usage

SPX is distributed as an ESM module and designed for usage in browser. You need to establish a connection to invoke the module.

import spx from 'spx';

spx.connect({
  fragments: [
    'menu',
    'main'
  ]
})(function (session) {

  // Callback is invoked on DOMContentLoaded.
  console.log(session)

});

An SPX connection will initialize an SPX session. In the above example we are targeting the <nav> and <main> element fragments. In your web application, ensure both elements exist for each page, for example:

<header>
  <nav id="menu">
    <a href="/">Home</a>
    <a href="/about">About</a>
  </nav>
</header>

<main id="main">
  <h1>Hello World!</h1>
</main>

Components

For more advanced cases, SPX provides component extendability. Register and connect components to DOM elements, and use attribute driven control for state, events, and element queries:

import spx from 'spx';

class Counter extends spx.Component {

  static define = {
    nodes: ['count'],
    state: {
      clicks: Number
    }
  }

  increment () {
    this.countNode.innerText = +this.state.clicks
  }
}

spx.register(Counter);

Connect the component to DOM elements, add the following to a defined fragment and allow SPX to do the rest:

<section spx-component="counter">

  Clicked: <span spx-node="counter.count">0</span>

  <button type="button" spx@click="counter.increment">
    Increment
  </button>
</section>

Contributing

Contributions are welcome! This project uses pnpm for package management and is written in TypeScript.

  1. Ensure pnpm is installed globally npm i pnpm -g
  2. Leverage pnpm env if you need to align node versions.
  3. Clone this repository git clone https://github.com/panoply/spx.git
  4. Run pnpm i in the root directory
  5. Run pnpm dev for development mode

Developing

The project uses tsup for producing the distributed bundle. The test directory contains real-world web application that is spun up within via 11ty.

pnpm dev         # Development in watch mode
pnpm build       # Bundle distribution builds for production
pnpm docs        # Documentation development environment
pnpm test        # Spins up the testing web application

License

Licensed under CC BY-NC-ND 4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.