Skip to content

blikblum/nextbone

This branch is 409 commits ahead of, 175 commits behind jashkenas/backbone:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

48a2286 · Mar 18, 2025
May 3, 2023
Feb 8, 2020
Jan 5, 2023
May 3, 2023
Mar 18, 2025
May 1, 2023
Jul 28, 2024
Feb 12, 2024
May 3, 2023
Mar 10, 2019
Jan 5, 2023
Jul 30, 2013
Feb 8, 2019
Apr 21, 2024
Feb 12, 2024
Jun 17, 2019
Oct 27, 2024
Feb 1, 2020
Jul 28, 2024
Feb 6, 2019
Jul 3, 2021
May 1, 2024
Jul 28, 2024
Feb 13, 2024
May 1, 2023
Jul 28, 2024
Dec 24, 2024
Jun 27, 2021
Jul 28, 2024

Repository files navigation

Nextbone

Nextbone is a conversion of venerable Backbone using modern Javascript features. It also replaces the View layer by a set of utilities to integrate with Web Components.

Features

  • Keeps Backbone features / behavior with minimal changes. In fact, most of the code is untouched
  • Uses EcmaScript Modules and Classes
  • Fully tree shackable
  • Seamless integration with Web Components (specially LitElement)

Install

$ npm install nextbone

To take fully advantage of nextbone is necessary to use Typescript or Babel configured with @babel/plugin-proposal-decorators and @babel/plugin-proposal-class-properties plugins

Usage

Examples uses language features (class properties and decorators) that needs transpiling with Babel or Typescript

Define models

import { Model, Collection } from 'nextbone'

class Task extends Model {
  static defaults  = {
    title: '',
    done: false
  }
}

class Tasks extends Collection {
  static model = Task
}

const tasks = new Tasks()
tasks.fetch()

Define a web component using LitElement

Without decorators

import { LitElement, html} from 'lit'
import { view, delegate } from 'nextbone'

class TasksView extends view(LitElement) {
  static properties = {
    // set type hint to `Collection` or `Model` to enable update on property mutation
    tasks: { type: Collection }
  }

  constructor() {
    super()
    this.tasks = new Tasks()
    delegate(this, 'click', '#fetch', this.fetchTasks)
  }

  fetchTasks() {
    this.tasks.fetch()
  }

  render() {
    return html`
    <h2>Tasks</h2>
    <ul>
      ${tasks.map(task => {
        html`<li>${task.get('title')}</li>`
      })}
    </ul>
    <button id="fetch">Fetch data</button>
    `
  }
}

customElements.define('tasks-view', TasksView)

document.body.innerHTML = '<tasks-view></tasks-view>'

With decorators

import { LitElement, html, property } from 'lit'
import { state, eventHandler } from 'nextbone'

@view
class TasksView extends LitElement {
  // use specialized `state` decorator
  @state
  tasks = new Tasks()

  // or use `property` decorator with type hint = `Collection` or `Model`
  @property({ type: Collection })
  tasks = new Tasks()

  @eventHandler('click', '#fetch')
  fetchTasks() {
    this.tasks.fetch()
  }

  render() {
    return html`
    <h2>Tasks</h2>
    <ul>
      ${tasks.map(task => {
        html`<li>${task.get('title')}</li>`
      })}
    </ul>
    <button id="fetch">Fetch data</button>
    `
  }
}

customElements.define('tasks-view', TasksView)

document.body.innerHTML = '<tasks-view></tasks-view>'

Documentation

WIP

Related projects

Copyright © 2019-2024 Luiz Américo Pereira Câmara

About

Backbone reimagined with ES classes and web components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 78.7%
  • HTML 21.3%