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

@slydragonn/classyjs

v1.1.3

Published

Framework Frontend based on OOP and Atomic design

Downloads

4

Readme

Classy JS

A very small framework frontend based on OOP and Atomic design.

classyjs diagram

The main idea is to use javascript only when necessary, that's why the island concept.

Getting Started

A minimal app

import { mountIsland, Container } from "@slydragonn/classyjs"

const myApp = new Container({
  children: {
    text: "Hello World!",
  },
});

mountIsland(document.getElementById("island"), myApp)

Install

npm i @slydragonn/classyjs

A sample app built with vitejs:

npx create-classyjs-app@slydragonn/classyjs project-name

API

Mount Application:

mountIsland(root, atom)

Remove Atom:

import { Span } from "@slydragonn/classyjs"

const hello = new Span({
  children: "Hello World!"
})

hello.remove()

Atoms:

  • Container
  • Title
  • Text
  • Span
  • Button
  • ListItem
  • Option
  • Image
  • Link
  • Input

Initial State, Life Cycle and State Update for Container, Link, ListItem:

import { mountIsland, Container } from "@slydragonn/classyjs";

/*
the classes of Container, Link and ListItem can had many children
1: Initial State
2: Life Cycle to listen the mount and unmount

1. Initial State:
    * props: properties of a HTML Element like style.
    * children: object with many children like atoms, numbers or text.
    * events: events of a HTML Element like click, change.
    * attrs: Attributes of the HTML Element like class, id.
2. Life Cycle:
    * mount: a function that runs when an element is mounted
    * unmount: a function that runs when an element is unmounted
*/

const example = new Container(
  {
    props: {},
    children: {
      text: "Hello World!",
    },
    events: {
      click: () => console.log("Hello"),
    },
    attrs: {
      class: "container",
    },
  },
  {
    mount: () => console.log("Atom did mount"),
    unmount: () => console.log("Atom did unmount"),
  },
);

/*
Update the State: All initial state can be updated 
using the update method. You can also listen to the 
update with the second parameter that accepts a callback
*/
example.update(
  {
    children: {
      text: "new Children",
    },
  },
  (state) => console.log(state),
);

Children for Title, Text, Span, Button and Option:

import { Span } from "@slydragonn/classyjs"

// the atoms Title, Text, Span, Button and Option only accepts one child
const text = new Span({
  children: "I am a span"
})

Image and Input don't accept children.

Molecules:

  • List
  • Select Accept an Array as children:
import { List, ListItem } from "@slydragonn/classyjs"

const numbers = [1, 2, 3, 4, 5]

const myList = new ListItem({
  children: numbers.map(number => {
    return new ListItem({
      children: {
        value: number
      }
    })
  })
})

Context

Create a global state store in the browser session storage.

import { createContext } from "@slydragonn/classyjs";

/*
Accept two params:
  1. context name
  2. initial State
And return two values:
  1. initial State
  2. setState function: accept a callback that receives state as a parameter

*/
const { initialState, setState } = createContext("counter", 0);

setState((state) => state + 1);