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

marionette-lite

v0.0.5

Published

Extended marionette components for simplified work

Downloads

2

Readme

Marionette Lite v0.0.4

Build Status JavaScript Style Guide downloads version license

This project provides a prepared components for simplified work with Backbone.Marionette. In examples used ES5 syntax, but you can use components with ES3.

Main features:

  1. Controller with filters (before, afrer, async, for authorizate and so on) [since v0.0.4]
  2. Error route and add route events [since v0.0.4]
  3. Cached collection and model (in the localStorage or memory) [since v0.0.5]
  4. Container fetch, destroy methods to fetchPromise and destroyPromise [since v0.0.6]

Depndencies: Marionette >=3

Installation

Add the script to the page after backbone.marionette.js has been included:

<script src="/path/to/backbone.marionette.js"></script>
<script src="/path/to/marionette-lite.js"></script>

or if you're using AMD, require the script as a module:

require(['path/to/marionette-lite.js']);

Note that the AMD module depends on underscore, backbone, marionette modules being defined as it lists them as dependencies. If you don't have these mapped, you can do it by adding the following to your require config:

requirejs.config({
  paths: {
    backbone: 'actual/path/to/backbone.js',
    underscore: 'actual/path/to/underscore.js'
  }
});

If you are using CommonJS or ES5 modules, install via npm:

npm install marionette-lite --save

then require it in your modules:

// CommonJS
var marionette-lite = require('marionette-lite');

//ES5 modules
import * as MarionetteLite from 'marionette-lite';
// or include some components:
import { Router, Controller, /* ... */ } from 'marionette-lite';

Usage

###Filter

filters works by overriding Backbone.Router.prototype.route method. Whenever a router's route method is called, its wraps the route callback (or route handler) that's passed in a 'wrapper handler', that calls before or after "filters" you have written along with the original route callback. So, we used marionette, filters is set into controller

You have the ability to define functions to be run before and after a route has fired. This has huge benefits for keeping Router flexible. To define a before and after filter, simply create respectively named objects on your Controller along with a key/val set matching filter and controller's action.

Example:

import { Filter } from 'marionette-lite';

const RequresAuthFilter = Filter.extend({
  // name is used in controller for detect filter
  name: 'requresAuth',
  
  // async mode
  async: true,
  
  // by default execute before routing trigger
  execution: Filter.Before, 
  
  // func which fired as filter
  handler(fragment, args, next) {
    // Requesting server to check if user is authorised
    $.ajax({
      url: '/auth',
      success: () => {
        this.isSignedIn = true;
        next();
      },
      error: () => {
        Backbone.navigate('login', true);
      }
    });
  },
});

or

import { Filter } from 'marionette-lite';

const GoogleTrackPageView = Filter.extend({
  name: 'googleTrackPageView',
  execution: Filter.After, 
  handler(fragment, args) {
    /* Google analytics tracking handlers */
    return true;
  },
});

If you want use async handlers, you should calling next callback (third argument) when filter finished. If you use sync handler (by default), you should return true to continue route handling or return false (e.g. call Backbone.navigate('login', true))

####How use it in your project ?

You should use Router from this package (extended from Marionette.AppRouter) and add filters to your controller as:

import { Router } from 'marionette-lite';
const AwesomeRouter = Router.extend({ /* add your routes */ });
// ....

import * as Filters from './{path/to/your/filters}'; // include your filters

// create array with your filters
const filtersMap = () => [
  new Filters.RequresAuth(),
  new Filters.PreventAccessWhenAuth(),
  new Filters.GoogleTrackPageView()
];

const AwesomeController = Marionette.Object.extend({
  // Add available filters map
  filtersMap,

  filters: {
    // e.g. Action that need authentication and if user is not authenticated 
    // gets redirect to login page
    requresAuth: ['logout', 'user'],

    // e.g. Action that shouldn't be accessible if user is authenticated
    // for example, login, register, forgetpasword ...
    preventAccessWhenAuth: ['login', 'signup'],

    // Can use `*` for all actions
    // e.g.Google analytics tracking
    googleTrackPageView: ['*']
  },

  // actions
  home() { this.changeView(new HomeView()); },
  
  login() { this.changeView(new LoginView()); },
  
  signup() { this.changeView(new SignUpView()); },
  
  user(id) {
    const user = new Models.User({ id });
    user.fetch({
      success: () => this.changeView(new UserView(id)),
      error: () => false // handle error
    });
  }
});

API

soon...

Development

Clone the repository and install the dependencies. Do not forget to install globally webpack if installed yet.

$ git clone https://github.com/noveogroup-amorgunov/marionette-lite my-project
$ cd my-project
$ npm install

To build the project run the follow command. It will compile the project and put the result under dist directory. Also it will watch files changes and compile project again.

$ npm run bundle
$ npm run watch #run webpack with watching

To test project run:

$ npm test