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

funco

v0.0.5

Published

Funco is a small **experiment of functional components** based on vdom.

Downloads

8

Readme

Funco

Funco is a small experiment of functional components based on vdom.

import {h,render} from "funco";

function App(props,{set,get}){
   return <button click={()=>set("Funco!")}>
       hello {get()||""}
   </button>
}

render(
   <App/>,
   document.querySelector("#app")
)

All function with Funco, is a component with a micro state.

Functional component

A component based on funco, can read 3 arguments.

  1. props : Properties associated with the component.
  2. state : Component status controller.
  3. context : Context given to the component from a higher level.
function Component(props,state,context){
   return <div>
       {props.children}
   </div>
}

every time you run state.set(), it rerender the view associated only with the component.

State

The state of each component is read by using state.get () and is updated by using state.set ().

function Component(props,state,context){
   return <button click={()=>state.set("Funco!")}>
       hello {state.get()||""}
   </button>
}

You can use {set, get} to directly access state.set and state.get.

Context

You can share states by using the context=<any> property, associated with the component.

render(
   <App context={[1,2,3]}/>,
   document.querySelector("#app")
)

You can define an initial context simply as property.

function App(){
   return <OtherComponent context={[1,2,3,4]}/>
}

You can modify the context simply by defining yourself as a property.

Children

Unlike React, Funco forces every child associated with the component to be a virtual node.

As an author I do not find coherent the use of props.children[0], to access a function.

<App>
{()=>{
   /** It doesn't work **/
}}
</App>

I strongly recommend associating it with a property since, in the opinion of the author, I find it more readable, and adapts to the best definition and type checking.

<App fun={()=>{

}}/>

High order components

Funco uses Map on the nest, to store the function associated to the component, you can share between multiple components a specific node of the document without any problem.

Warning, please do not try to create local components within the component, as this prevents the state of the component from being stored.

Lifecycle

I've got some ideas from Hyperapp ❤️ Funco.

create

It is executed once the tag is created.

<h1 create={(target:HTMLElement)=>{
   /** any **/
}}>
   Hello!
</h1>

remove

It runs once the label has been removed from the main node.

<h1 remove={(target:HTMLElement)=>{
   /** any **/
}}>
   Hello!
</h1>

update

It runs once the view associated with the tag is rendered, if update returns false, it will not propagate the change to its children.

<h1 update={(props:Object, target:HTMLElement)=>{
   /** any **/
}}>
  Hello!
</h1>