A lightweight, zero-dependency JavaScript library for building component-based web applications with efficient communication, navigation, and state persistence.
- Component-Based Architecture: Uses Web Components (Custom Elements) for reusable UI
- Lazy Hydration: Visibility-driven component initialization for improved performance
- Universal Messaging:
multicall()function for communication between components - Navigation System: View switching with state persistence and history support
- State Persistence: URL hash-based state storage for bookmarking and sharing
- REST API Interface: Simple API client with endpoint definition and mocking
- TypeScript Support: Full TypeScript implementation available
- Framework Agnostic: Works standalone or as a complement to other libraries
# Coming soon to npm<script type="module">
import { multicall } from './lib/jsum.js';
// Define a custom element
customElements.define('my-component', class extends HTMLElement {
connectedCallback() {
this.setAttribute('jsum', ''); // Enable lazy hydration
}
sayHello() {
console.log('Hello from my component!');
return 'Hello!';
}
});
// Call methods on all matching components
multicall('my-component', 'sayHello');
</script>- jsum.js: Core hydration and messaging functionality
- navigation.js: View switching and state management
- menu.js: Navigation menu components
- persistance.js: State persistence using URL hash
- API.js: REST API client with mocking support
- object_equals.js: Deep object comparison utilities
- jsum.ts: TypeScript implementation of core functionality with type definitions
- navigation.ts: Typed view switching and state management
- menu.ts: Typed navigation menu components
- persistance.ts: Typed state persistence using URL hash
- API.ts: Typed REST API client
- object_equals.ts: Typed deep object comparison utilities
- Start the test server:
npm run test:server - Open
http://localhost:3000/_test_core/index.htmlorhttp://localhost:3000/_test_navigation/index.html
The project uses Nightwatch.js for automated browser testing:
-
Install dependencies:
npm install
-
Start the test server in one terminal:
npm run test:server
-
Run the tests in another terminal:
npm test
Test files are organized in the tests/ directory:
tests/core/hydration.test.js- Tests for component hydration functionalitytests/core/multicall.test.js- Tests for the messaging systemtests/navigation/navigation.test.js- Tests for navigation components
The automated tests validate:
- Visibility-based hydration of components
- Component messaging using multicall
- Navigation between views
- URL hash-based state persistence
The library includes a full TypeScript implementation in the ts/ directory.
npm run build:tsThis compiles TypeScript files from ts/src/ to JavaScript in ts/dist/.
npm run watch:tsThis watches for changes to TypeScript files and recompiles them automatically.
<script type="module">
import { multicall } from './ts/dist/jsum.js';
// Use the TypeScript-generated version with type safety
</script>For more details, see the TypeScript README.
JSUM can complement existing front-end libraries and frameworks:
- Cross-Framework Communication: Use
multicall()as a universal message bus between different framework components - Micro-Frontend Architecture: Bridge communication between React, Vue, or Angular islands
- Performance Enhancement: Add visibility-based lazy loading to components in any framework
- State Persistence: Lightweight alternative to complex state management libraries
- Incremental Migration: Facilitate gradual transitions between frameworks with a common messaging layer
- Server-Side Rendering: Enhance SSR frameworks with on-demand component hydration
The zero-dependency nature and Web Components foundation make JSUM particularly valuable for applications using multiple frameworks or transitioning between technologies.
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2024 jameshickman