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

knockout-jsx

v1.0.3

Published

Use JSX with Knockout.

Downloads

6

Readme

knockout-jsx

Use JSX with Knockout.

JSX is not coupled to React. This little library will enable its use with Knockout instead.

Installation

Install knockout-jsx through npm.

npm install --save knockout-jsx

Once installed, knockout-jsx supports several types of imports.

ES6

import { registerJSXComponent } from 'knockout-jsx';

CommonJS

const { registerJSXComponent } = require('knockout-jsx');
// Or...
const knockoutJSX = require('knockout-jsx');

UMD

Referencing either dist/knockout-jsx.js or dist/knockout-jsx.min.js will add the API methods to ko.jsx.

<script src="node_modules/knockout-jsx/knockout-jsx.js"></script>
<!-- Or... -->
<script src="node_modules/knockout-jsx/knockout-jsx.min.js"></script>

Usage

Build Step

JSX must be transpiled to DOM API methods prior to using this libary. nativejsx is recommended. See the build tools section of the nativejsx readme for instructions on use with Webpack, Gulp, Grunt, or a shell command.

Components

This library uses Knockout Components and registers components with ko.components.register().

import { registerJSXComponent } from 'knockout-jsx';

function CounterViewModel() {
    const self = this;
    self.counter = ko.observable(0);
    self.counterText = ko.computed(() => `Counter is at ${self.counter()}`);
    self.incrementCounter = () => self.counter(self.counter() + 1);
}

const template = (
    <div>
        <div data-bind="text: counterText"></div>
        <button type="button" data-bind="click: incrementCounter"></button>
    </div>
);

registerJSXComponent('counter', { viewModel: CounterViewModel, jsxTemplate: template });

Then, in the page markup:

<body>
    <h2>Here's a counter!</h2>
    <counter><!-- component will be rendered here by Knockout --></counter>
</body>

API

registerJSXComponent(name, component)

Registers a given component with Knockout. This is just a wrapper for ko.components.register.

Arguments

  • [name] (String): The name of the component. This is the HTML element where a component will be rendered. For example, if a component with the name 'counter' is passed to this method, the component will be rendered wherever a <counter></counter> tag appears in the page markup. The value of name must be all lowercase.
  • [component] (Object): The component object. This must have the following properties:
    • [viewModel] (Function): The view model definition for the component.
    • [jsxTemplate] (Object): The JSX template object to use for the component. A build tool must convert the JSX markup to DOM API methods prior to calling registerJSXComponent. As such, this should actually be an Element.

Testing

Run npm run test to start the Karma test runner with PhantomJS. To just run the tests once, run npm run test-once.

License

Licensed under the MIT License.