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

@sebgroup/extract

v3.0.2

Published

Base library for framework components.

Downloads

24,842

Readme

@sebgroup/extract

Extract is considered deprectaed in favor of implementing shared functionality as Web Components. See https://github.com/sebgroup/green/tree/main/libs/core


Extract is where all the business logic of Green components lives so that it can be shared between Angular and React implementations. It is called Extract since the normal way of creating a component is within Angular and React and then extracting the common logic.

Patterns for common components

The look

Step one is always creating CSS and HTML for your component in Chlorophyll. We use Storybook to visualise the component in various states so that we can track progress and continuously check that it adheres to design guidelines. Read more in https://github.com/sebgroup/green/libs/chlorophyll

Interaction and data

A common component consists of two parts: An interaction object and the data. Let's look at these through an example.

type Operator = '+' | '-' | '*' | '/' | '='
type Digit = number | '.'
type Press = Operator | Digit

export interface Calculator {
  pressDigit: (digit: Digit) => void
  pressOperator: (operator: Operator) => void
  clear: () => void
}

export interface CalculatorData {
  currentValue: number
  numpad: Digit[][]
  operators: string[]
  presses: Press[]
}

These are the components we will be interacting with. The Calculator instance will be persistent and allows us to interact while the CalculatorData is changed on every interaction and allows us to render our component.

Now, lets create out Calculator.

export interface CalculatorOptions {
  containerEl: HTMLElement
}

export const createCalculator = (listener: (data: CalculatorData) => void, options: CalculatorOptions): Calculator => {
  // Create initial data
  let data: CalculatorData = {
    currentValue: 0,
    numpad: [
      [7, 8, 9],
      [4, 5, 6],
      [1, 2, 3],
      [0, '.'],
    ],
    operators: ['/', '*', '-', '+', '='],
  }

  // Create interaction object
  const calculator: Calculator = {
    clear: () => {
      data = clear(data) // pure function
      listener(data)
    },
    pressDigit: (digit) => {
      data = pressDigit(data, digit) // reducer
      listener(data)
    },
    pressOperator: (operator) => {
      data = pressOperator(data, operator) // reducer
      listener(data)
    },
  }

  // Add keyboard interactions to element
  // options.containerEl

  // Call listener with initial data
  listener(data)
}

All interactions with the calculator is done through pure functions with no side effects using a reducer pattern (basically a data structure goes in and a new, changed data structure comes out). These are easily testable. The resulting updated data model is communicated to the framewoek of choice which can then re-render making it easily bindable.