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

backbone-ts-decorators

v1.0.0

Published

This library provides Typescript decorators to ease your use of Backbones with Typescript.

Downloads

1

Readme

backbone-ts-annotations

Purpose

This library provides Typescript decorators to ease your use of Backbones with Typescript. At first, it intends to mitigate some issues encountered with Bakcbone that doesn't mix well with ES6 (and so Typescript) classes and extend. But it also Aspect Oriented Programming to your code making the configuration of your view and model in your place, and lets you focus on the business logic of your views and models.

Installation

npm install backbone-ts-decorators

API

BackboneViewProperties

Use it to decorate your views, to provide all the basis so for Backbone to initialise it.

Usage

@BackboneViewProperties({  
    events: {  
        "click button.save": "save"  
    },  
    template: template  
})  
export class LittleChildView extends BaseView<Person>{  
    save() {  
        this.model.save();  
    }  
}

The annotations take a single argument which is a BackboneViewOptions. Here are the properties, note that they are all optionnal:

  • template type: (...args:any[]) => string
    The function the view will use to generate the HTML. As defined in Backbone documentation, it's to enforce convention, but it's up to you to implement the render function and call it in your fashion.
  • events type: { [key:string]:string }
    The hash of events your view will handle. Note that for now, there is no inheritance on events. So if you have a view that inherits from another and also defines its own events, you'll need to declare again parent's view events if you need them. Maybe an inheritance mechanism will be implemented later.
  • tagName type: string
    The DOM element which will be the root element of your View.
  • className type: string
    The class that will be append to your View element.
  • id type: string
    The DOM id your view will have in the DOM.
  • el type: string
    DOM element to which your view will be attached.

BackboneModelAttribute

Use it to decorate your property in your Typescript class to that it auto generates getter/setter that fits Backbone, while using directly the property.

Which means you can now do console.log(myModel.value) and under the hood it will do console.log(myModel.get("value"); and myModel.value = 42 will do myModel.set("value",42).

usage

class Person extends Model {  
    @BackboneModelAttribute()  
    firstName:string;  
    @BackboneModelAttribute()  
    lastName:string;  
}

Inside the @BackboneModelAttribute() you can optionnaly pass a string which will be used as the attribute name in your Backbone model. If none is provided, the property name is used as the attribute name.