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

xclient

v0.3.0

Published

xclient tools

Downloads

4

Readme

XClient

A set of tools and notes from my experiences of building middle scale projects.

Notes

Tools Categories

Setup

Installation

npm i --save xclient
npm i --save react react-dom

Import Tools

import {xxx} from 'xclient'

Tools Api

createCachedPages

func(options): component

create a react class CachedPages, which will render and cache pages by location and routes.

  • options
    • cacheTime - milliseconds, default to 5 * 60 * 1000
    • cacheLimit - default to 5
  • props of CachedPages
    • location - location state described in bindLocation
    • routes - a collection of routes as an object, where key is route id and value is route. the route.options are:
      • page - page component
      • [cacheTime] - cacheTime for this route

composeAll

func(...composers)(component): component

compose component with all composers.

  • composer - func(component): component

connectLocation

func([mapper])(component): component

create a container for a component to provide it with location state.

  • mapper - function, string or object
    • function - func(location): props
    • not provided - the whole state is mapped to props.location
    • string - the whole state is mapped to props.key, where key is this value
    • object - for each item, key is the prop key and value is the path of state. if value is falsy, the key is also used as the state path

connectStore

func(store)([mapper])(component): component

create a container for a component which is connected to the store and will map the state of the store to the props of the component when the state update.

  • mapper - function, string or object
    • function - func(newState, oldState): props
    • not provided - the whole state is mapped to props.state
    • string - the whole state is mapped to props.key, where key is this value
    • object - for each item, key is the prop key and value is the path of state. if value is falsy, the key is also used as the state path

Link

component

a normal link component as <a/> except that if props.href is specified, clicking it will not trigger page reloading but only change the url.

locationState

singleton

a singleton representing the browser location and providing apis to get, manipulate and listen to changes of the location.

  • methods
    • getPath(): string - return the pathname with query string
    • getPathname(): string - return the pathname
    • getQuery(): object - return the query object
    • setPath(path)
    • setPathname(pathname)
    • setQuery(query)
    • subscribe(callback): id - callback is func({path, pathname, query})
    • unsubscribe(id) - id is the id returned from subscribe

mountRootView

func(node)

mount root view component into body.

Pages

component

render pages by location and routes.

  • props
    • location - location state described in bindLocation
    • routes - a collection of routes as an object, where key is route id and value is route. the route.options are:
      • page - page component

Route

class

A route is defined by a path pattern.

  • methods
    • constructor(pathPattern, options)
      • pathPattern - a pattern to define the route, it can be:
        • a normal path, such as /some/page
        • a path with param placeholders, such as /users/:userId
        • * which will match any path
      • options - any options which can be found as route.options
    • match(path): params - try to match a path and get the params, return {} if match without any params, return false if not match
    • path(params, query): path - format a path
    • go(params, query) - format a path and change the url to it

Router

class

A router is a collection of routes and provide a set of methods for convenience

  • methods
    • constructor([routes]) - init the router with optional routes
    • route(id, path, options) - define a route
    • setRoute(id, route)
    • setRoutes(id, routes)
    • match(path): {id, params, route} - try to match a path. return undefined if no matched route
    • path(id | pathname, params, query) - build path
    • go(id | pathname, params, query) - build path and go to it
    • current() - try to match by current pathname

Store

class

a reactive state store.

  • methods
    • constructor(initialState) - initialState must be an object if provided
    • set(path, value)
    • get(path, value)
    • unset(path)
    • subscribe(callback): id - callback is func(newState, oldState);
    • unsubscribe(id) - id is the id returned by subscribe

updateByProps

func([...props], [deep])(component): component

create a container for a component which will only update if props change.

  • props - strings, specify which props should be compared. if not provided, all props will be compared.
  • deep - a boolean flag which indicate if the props should be compared deeply.

License

MIT