npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backdraft-app

v1.3.3

Published

Plugin-based UI application framework built on top of and extending Backbone to create single page apps

Downloads

888

Readme

Backdraft

Wrapper around Backbone providing integration with DataTables, as well as other utilities for creating Backbone views and models. Written as a plugin-based framework, where the DataTables integration is a plugin itself, and Backdraft can be further extended with your own plugins.

Install

npm install backdraft-app

Usage

First, define a new Backdraft app:

// app.js
import MainRouter from "./main_router";

import App from "backdraft-app/src/app";

class TableExample extends App {
  activate($el) {
    this.mainRouter = new MainRouter({ $el });
    Backbone.history.start({ });
  }
}

Define an entry point for creating your app:

// main.js
import TableExample from "./app";

Backdraft.app("TableExample", new TableExample());

Define the various components of your app:

// main_router.js
import IndexView from "./views/index_view";

import Router from "backdraft-app/src/router";

export default class MainRouter extends Router {
  get routes() {
    return {
      "" : "index"
    };
  }

  index() {
    const view = new IndexView();
    this.swap(view);
  }
};

// models/book.js
import Model from "backdraft-app/src/model";

export default class Book extends Model {
};

// collections/books.js
import Book from "../models/book";

import Collection from "backdraft-app/src/collection";

export default class Books extends Collection {
  get model() {
    return Book;
  }
};

// views/book_table_view.js
import BookRowView from "./book_row_view";

import LocalDataTable from "backdraft-app/src/data_table/local_data_table";

export default class BookTableView extends LocalDataTable {
  get rowClass() {
    return BookRowView;
  }
  
  get paginate() {
    return false;
  }
};

// views/book_row_view.js
import Row from "backdraft-app/src/data_table/row";

export default class BookRowView extends Row {
  get columns() {
    return [
      { bulk : true },
      { attr : "name", title : "Name" },
      { attr : "created_at", title : "Created" }
    ];
  }
};

Now create the view that pulls all the pieces together:

// views/index_view.js
import BookTableView from "./book_table_view";
import Books from "../collections/books";

import View from "backdraft-app/src/view";

export default class IndexView extends View {
  render() {
    const collection  = new Books();
    const data = [];
  
    // fake data
    for (let iter = 0; iter < 10; ++iter) {
      data.push({ name : `Book ${iter + 1}` });
    }
  
    collection.add(data);
    const table = new BookTableView({ collection });
  
    this.$el.html(table.render().$el);
    return this;
  }
}

Finally, in an HTML page that loads the above scripts, activate the app at load time:

<html>
  <head>
    ...
  </head>
  <body>
    <div id="example-area"></div>

    <script type="text/javascript">
      Backdraft.app("TableExample").activate($("#example-area"));
    </script>
  </body>
</html>

Legacy Usage

The legacy usage uses the Backdraft object to define the components of the application.

First, define a new Backdraft app and what plugins it will use:

Backdraft.app("TableExample", {
  plugins : ["DataTable"],

  activate : function($el) {
    this.mainRouter = new this.Routers.Main({ $el : $el });
    Backbone.history.start({ });
  }
});

Now, everything else gets namespaced within the Backdraft app name:

// routers/main.js
Backdraft.app("TableExample", function(app) {
  app.router("Main", {
    routes : {
      "" : "index"
    },

    index : function() {
      var view = new app.Views.Index();
      this.swap(view);
    }
  });

});

// models/book.js
Backdraft.app("TableExample", function(app) {
  app.model("Book", {});
});

// collections/book.js
Backdraft.app("TableExample", function(app) {
  app.collection("Books", {
    model : app.Models.Book
  });
});

// views/book_table.js
Backdraft.app("TableExample", function(app) {
  app.view.dataTable("BookTable", {
    rowClassName : "BookRow",
    paginate : false
  });
});

// views/book_row.js
Backdraft.app("TableExample", function(app) {
  app.view.dataTable.row("BookRow", {
    columns : [
      { bulk : true },
      { attr : "name", title : "Name" },
      { attr : "created_at", title : "Created" }
    ]
  });
});

Now create the view that pulls all the pieces together:

// views/index.js
Backdraft.app("TableExample", function(app) {
  app.view("Index", {
    render : function() {
      var collection  = new app.Collections.Books();
      var data = [];

      // fake data
      for (var iter = 0; iter < 10; ++iter) {
        data.push({ name : "Book " + (iter + 1) });
      }

      collection.add(data);
      var table = new app.Views.BookTable({ collection : collection });

      this.$el.html(table.render().$el);
      return this;
    }
  });
});

Finally, in an HTML page that loads the above scripts, include the dist/backdraft.js file in your assets. You must also include the required vendor files (jQuery & underscore.js), plus dataTables.js if using the datatables plugin.

Then activate the app at load time:

<html>
  <head>
    ...
  </head>
  <body>
    <div id="example-area"></div>

    <script type="text/javascript">
      Backdraft.app("TableExample").activate($("#example-area"));
    </script>
  </body>
</html>

Examples

If you run yarn run examples, a local server will be launched with live examples at localhost:9888.

Develop & Contribute

Environment Setup

To develop a Backdraft plugin or modify Backdraft, the following setup needs to be done first (this assumes a Mac running OS 10.9+):

  • Install NVM, the Node Version Manager https://github.com/creationix/nvm

  • curl https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | sh

  • Open a new tab in your terminal

  • Install Node.js with:

  • nvm install v6.11.0

  • Set it as the default Node.js version

  • nvm alias default v6.11.0

  • Install Yarn https://yarnpkg.com/en/docs/install

  • Install dependencies

    cd backdraft
    yarn run setup
    yarn install

Testing

Run the yarn dev script from the main directory to have the source and test files watched and tests auto-run when any modifications are done

yarn run dev

Run the specs script to run all the tests and exit

yarn run specs

Use the following two ENV variables to target specific tests:

  • SPEC_FILTER - target specific tests via karma-jasmine's --grep feature.

  • SPEC_FILE_FILTER - target specific tests by file path. This value must be a regex. For example:

    SPEC_FILE_FILTER="/data_table.*_spec.js/" yarn run specs

See all available commands with:

yarn run

Contributing

If you'd like to contribute a feature or bugfix: Thanks! To make sure your change has a high chance of being included, please read the following guidelines:

  1. Post a pull request.
  2. Please add tests. We will not accept any patch that is not tested. (It's rare when explicit tests aren't needed.) Please see existing tests for examples and structure.

Thank you to all the contributors!

Publishing - admins

To publish a new version to NPM (https://www.npmjs.com/package/backdraft-app), do the following

  1. Ensure the following are complete:
  • Tested
  • Green build
  • Code Reviewed
  1. Publish new version: yarn version --new-version <version>:
  • creates commit with version change
  • tags the commit with the version
  • pushes the commit and tag to Github
  • builds and publishes the node module
  1. If on a branch, ensure this version gets merged to master

License

Backdraft is Copyright © 2014-2018 Invoca, Inc. MIT license.