This is an interactive tutorial for learning Element.js, a native JavaScript framework that runs without transpilation.
The tutorial is organized into progressive lessons:
- Welcome (
/tutorial/welcome
) - Introduction to Element.js and basic component creation - Lifecycle (
/tutorial/lifecycle
) - Component lifecycle methods and rendering - State Management (
/tutorial/state
) - Reactive state with observe$ and component state$ - Communication (
/tutorial/communication
) - Component communication and messaging (planned) - Server Integration (
/tutorial/server
) - Server-side rendering and API integration (planned) - Advanced Features (
/tutorial/advanced
) - Advanced patterns and best practices (planned)
- Interactive Code Editor: Write and test Element.js components directly in the browser
- Live Demos: See components in action with real-time updates
- Progressive Learning: Each lesson builds on the previous one
- Server-Side Rendering: Demonstrates both client and server capabilities
- Reactive State Management: Learn about observe$ and global app state
createComponent$("my-component", (el) => {
el.define$({
template$: () => `<div>Hello World</div>`,
style$: () => `[component] div { color: blue; }`,
onInit$: async () => {/* initialization */},
onRender$: async () => {/* rendering logic */},
onHydrate$: async () => {/* client-side hydration */},
});
});
const [state, watchState] = observe$({
count: 0,
items: [],
});
// Watch for changes
watchState((target, key, value) => {
console.log(`${key} changed to:`, value);
});
import { appState$ } from "./element.js";
// Persistent state across page reloads
appState$.user = { name: "John", preferences: {} };
- Start a JSphere server or any static file server
- Navigate to
/tutorial/welcome
to begin - Follow the navigation between lessons
- Try the interactive code examples
tutorial_app/
├── client/
│ ├── components/
│ │ └── pages/
│ │ ├── index/ # Home page
│ │ └── tutorial/ # Tutorial lessons
│ │ ├── welcome/ # Lesson 1
│ │ ├── lifecycle/ # Lesson 2
│ │ └── state/ # Lesson 3
│ └── css/
│ └── global.css # Global styles
├── server/
│ └── index.ts # Server-side routing
└── shared/
├── element.js # Element.js framework
├── dependencies.js # Component registry
└── jsphere.d.ts # TypeScript definitions
- No Build Step: Components work directly in the browser
- Server-Side Rendering: Full SSR support with hydration
- Component Lifecycle: onInit$, onRender$, onHydrate$ methods
- Reactive State: observe$ function for reactive data
- Scoped Styling: Component-scoped CSS with [component] selector
- Client/Server Code Sharing: Same components work on both sides
- Progressive Enhancement: Components hydrate seamlessly
- Built-in Routing: URL-based navigation with history API
This tutorial showcases Element.js as a modern, native JavaScript framework that eliminates the need for complex build tools while providing powerful features for building interactive web applications.