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

mblocks

v1.0.4

Published

Library by Alex Merced of AlexMercedCoder.com (AlexMercedCoder.com/jslib)

Downloads

6

Readme

mBlocks

Library by Alex Merced of AlexMercedCoder.com (AlexMercedCoder.com/jslib)

Purpose

Alex Merced first created a front-end UI library using the Web Component API called MercedUI that gives you many of the features developers are used to in frameworks like React. Although, the Web Component API is still not fully supported in all browsers which is why the default is still to use frameworks like React, Angular and Vue. Is to make use of these frameworks often needs lots of tooling, transpilation, etc. to get full benefit from. mBlock is meant to provide features like reactive state props but in a form that doesn't need transpilation, the web component API or other tooling to get started.

Installation

CDN

<script src="https://res.cloudinary.com/dithdroai/raw/upload/v1609693921/libraries/block_y8xutn.js" charset="utf-8" defer></script>

Webpack Build

using webpack template

npx create-mblocks-app projectName

NPM

npm i mblocks

in your javascript file

const {Block} = require("mblocks")

ES6 Module

index.html

<script type="module" src="app.js" charset="utf-8" defer></script>

app.js

import {Block} from "https://res.cloudinary.com/dithdroai/raw/upload/v1609693921/libraries/blockmodule_vdhqao.js"

Getting started

Essentially all you need in your HTML to get started

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="block.js" charset="utf-8" defer></script>
        <script src="app.js" charset="utf-8" defer></script>
    </head>
    <body>
        <m-app id="start"></m-app>
    </body>
</html>

mBlock tags always start with the prefix "m-" before the tag name and an id to distinguish between instances.

The code underlying the tag would look like this in your app.js


//App Component
class App extends Block {
    constructor(id) {
        super({ name: 'app', state: { phrase: 'Hello World' }, id });
    }

    builder(state, props) {
        console.log(this.block.children);
        return `<h1>${state.phrase}</h1><m-test id=${props.id}></m-test>`;
    }

    assemble() {
        new Test(this.props.id);
    }
}

//the <m-test> component

class Test extends Block {
    constructor(id) {
        super({ name: 'test', state: { phrase: 'It Works' }, id });
    }

    builder(state, props) {
        return `<h1>${state.phrase}</h1>`;
    }

    assemble() {}
}

const app = new App('app');

in the constructor you pass a config object into super that configures element.

name: determines which tags trigger a render (tags that say m-element with the passed in ID)

state: the initial state which can be changed triggering a re-render with an call to instance.setState(newstate)

id: the id of the individual instance

there are fours function you should define...

builder(state, props) => a function that is passed the state and props objects and returns the template string to be rendered

assemble(state, props) => a function to run the constructors on any custom components included in your template

mount(state, props) => is run on the initial mounting of the component

update(state, props) => is run on every update triggered by setState

  • When the setState function is run it updates the state, then re-reruns the builder function, then the assemble is function is run to rebuild any custom components in your template.

That's it, just use setState to update any components state it should re-render and it will work! just remember to invoke constructors in assemble of children that are mBlocks (refer to the assemble function of the app component above.)