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

yaap-wire

v0.1.4

Published

yaap-wire plugin

Downloads

1

Readme

#Yaap-Wire plugin Build Status This project contains annotations that only work as a wire.js-plugin.

##wire.js Integration To use @Autowired (and annotations in general) in wire.js, simply add it as a plugin:

var wire = require("wire");
wire({
	level: "INFO",
	logger: {create:  './Logger'},

	plugins: [
		{module: "yaap/wire"}
	]
}, {require: require}).then(function(ctx){
	ctx.logger.log("message");
}, console.error);

Everything else is done by yaap, so you can start use your annotations:

//Logger.js

module.exports = {
  log: function(message, /*@Autowire*/ level){
		console.log(level + ": " + message);
	}
}

level references the value in the wire-context (with value "INFO") now.

Remark: Yaap/wire uses the parameter name to autowire. You can also supply a reference name with /*@Autowire("level")*/

Remark: You can also annotate the whole function with @Autowire so every parameter will be autowired by name.

##Wire annotations

  • @Autowired([<refName>]) (parameter/function/class): if a parameter is unassigned or null, a bean from the wire-context will be injected instead. If the annotation is placed at a parameter, the given refName or, if ommitted, the parameter-name will be used to resolve the reference. If the annotation is function-level, all parameters that are null or unassigned will be autowired by parameter-name. If the annotation is class-level, the parameter could be a string, an array of strings or an object that maps strings onto strings. New Properties according to the given names will be injected with the referenced beans.

  • @PostConstruct (function): the annotated function will be called after container finished configuring the bean.

  • @PreDestroy (function): the annotated function will be called, if context.destroy() is called.

##Express.js integration

There are also out-of-the-box annotations included for creating webapps in a springMVC-like manner. More information on how to setup this integration is available here A simple example of a service:

MyService.prototype = {
    index: function ()/*@GET*/ {
		return 'index';
    },

    submit: function (name, age)/*@POST @Param*/ {
     var msg = (age < 18)? "You are too young" : "You are welcome!";
	 return {view:'greet', model:{name: name, msg: msg}};
    }
};

As known from SpringMVC, the returned values determine, which view will be called and with what parameters. More details on this in my blogpost.

###browser-specific wire annotations for these annotations, you need to add the additional yaap/wire/html-plugin! (as shown in the browser-example)

  • @On(<refName>, <event>) (function): the annotated function will automatically be bound the the event of the given dom-node. This is intended to be used with the wire/dom-plugin. can reference one or more elements in the dom (though it is probably better practice to reference a bean in the wirecontext, which itself references the dom-nodes). For example, you could bind a clickhandler with this annotation: @On("dom.all!.btn","click"). The annotated method accepts one argument that is the event (though you could add additional @autowired arguments, if you want)

###Node-Specific wire-annotations (Express.js) for these annotations, you need to add the additional yaap/wire/express-plugin! (and you need to feed the express-application into the plugin as shown in the express-example)

  • @GET/POST/PUT/DELETE([<pathspec>]) (function): registeres the function as an endpoint in an express-application with either the given path or the functionname as path, if omitted.
  • @Param([<name>]) (parameter/function): fetches the annotated parameter from the query/path/post parameters. If annotation is on function-level, all parameters (except @Body-annotated parameters) are injected by-name.
  • @Body (parameter/function): if parameter-level, then the request-body will be injected. If on function-level, it states that the return-value will be returned as-is (Just like @ResponseBody does in SpringMVC).
  • @JSON (function): states, that the returned value will be send as response in json-format. (using response.json).
  • @Callback (parameter): a callback will be injected so you can return your response asynchronously. You can also simply return a promise, so you do not need to use a callback for asynchronous operations.