Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cradova

CodeDynasty-dev552Apache-2.03.13.2TypeScript support: included

Build Powerful ⚡ Web Apps with Ease

frontend library, PWA, webapp, SPA, Signal, VJS, vjs specification, cradova

readme


Logo

Cradova

Build Powerful ⚡ Web Apps with Ease

Explore the 🎙️ docs »

Join Community . Report Bug . Request Feature

Contributors Issues License npm Version License npm Downloads PRs Welcome Forks Stargazers

Cradova is 3

2025 - What's New? Function as reactive components

this can't be better anywhere XD

// functional components

const Cradova = function () {
  const [year, setYear] = useState(3, this);

  return h1("Cradova is " + year + " yrs old in ", {
    onclick() {
      setYear((lastYear) => {
        return lastYear + 1;
      });
    },
  });
};

// add reactivity to a signal element.
const counterSignal = new Signal({ count: 0 });
function count2() {
  useEffect(() => {
    let count = 0;
    setInterval(() => {
      count++;
      counterSignal.publish("count", count);
    }, 1000);
  }, this);

  return h1(" count: 0", {
    subscription: counterSignal.subscriber("count", function ({ count }) {
      this.innerText = " count: " + count;
    }),
  });
}

// converts to html and append to the Dom
document.body.appendChild(div(Cradova));

2024 - What's New? Signals pub/sub

import { Signal, getSignal, $if, $ifelse, div, h1 } from "cradova";

const signal = new Signal({ name: "john" });

function Hello() {
  const name = getSignal("name", this).name;
  return div(
    $if(name === "john", h1("Hello john")),
    $if(name === "paul", h1("Goodbye paul")),
    $ifelse(name === "john", h1("Hello john"), h1("Hello Paul"))
  );
}

signal.bind("name", this);
const html = div(Hello);
document.body.append(html);

setInterval(() => {
  signal.publish("name", "paul");
}, 5000);

2023 - What's New? Conditionals

import { $case, $if, $ifelse, $switch, div, h1 } from "cradova";

function Hello({ name }) {
  return div(
    $if(name === "john", h1("Hello john")),
    $if(name === "paul", h1("Goodbye paul")),
    $ifelse(name === "john", h1("Hello john"), h1("Hello Paul"))
  );
}

const html = div(Hello("john"), Hello("paul"));

function whatsAllowed({ age }) {
  return div(
    $switch(
      age,
      $case(12, h1("too young")),
      $case(26, h1("you are welcome")),
      $case(52, h1("too old"))
    )
  );
}

document.body.append(html, whatsAllowed({ age: 26 }));

2023 - What's New? Router

Router.BrowserRoutes({
  "/home": home,
});
// creates these routes
Router.navigate("/home", data);

2021 - first version

...

Contents

What is Cradova?

Cradova is a web development framework for building Single Page Applications and PWAs.

Cradova follows the VJS specification

What's the benefit?

Fast and simple with and fewer abstractions and yet easily composable.

Cradova is not built on virtual DOM or diff algorithms. Instead, State management is done in a way that is simple, easy and fast.

Is this a big benefit?

Undoubtedly, this provides a significant advantage.

current version changes

Installation

From npm

npm i cradova

CDN sources

<!-- unpkg -->
<script src="https://unpkg.com/cradova/dist/index.js"></script>
<!--    js deliver -->
<script src="https://cdn.jsdelivr.net/npm/cradova/dist/index.js"></script>

Examples

Some aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.

A basic component in Cradova

import { div, h1 } from "cradova";

function Hello(name) {
  return h1("Hello " + name, {
    className: "title",
    style: {
      color: "grey",
    },
  });
}

const html = div(Hello("peter"), Hello("joe"));

document.body.append(html);

Basic Samples

This a collection of basic examples that can give you some ideas

import {
  br,
  button,
  Function,
  createSignal,
  div,
  h1,
  reference,
  useRef,
} from "cradova";

// hello message

function HelloMessage() {
  return div("Click to get a greeting", {
    onclick() {
      const name = prompt("what are your names");
      this.innerText = name ? "hello " + name : "Click to get a greeting";
    },
  });
}

// reference (not state)

function typingExample() {
  const ref = useRef();
  return div(
    input({
      oninput() {
        ref.current("text").innerText = this.value;
      },
      placeholder: "typing simulation",
    }),
    p(" no thing typed yet!", { reference: ref.bindAs("text") })
  );
}

function App() {
  return div(typingExample, HelloMessage);
}

document.body.append(App());

Simple Todo list

Let's see a simple TodoList example

import {
  button,
  Function,
  createSignal,
  div,
  h1,
  input,
  main,
  p,
  useRef,
  useState,
} from "../dist/index.js";

// creating a store
const todoStore = new Signal({
  todo: ["take bath", "code coded", "take a break"],
});

// create actions
const addTodo = function (todo: string) {
  todoStore.publish("todo", [...todoStore.store.todo, todo]);
};

const removeTodo = function (todo: string) {
  const ind = todoStore.store.todo.indexOf(todo);
  todoStore.store.todo.splice(ind, 1);
  todoStore.publish("todo", todoStore.store.todo);
};


function TodoList() {
  // can be used to hold multiple references
  const referenceSet = useRef();
  // bind Function to Signal
  todoStore.subscribe("todo", todoList);
  // vjs
  return main(
    h1(`Todo List`),
    div(
      input({
        placeholder: "type in todo",
        reference: referenceSet.bindAs("todoInput"),
      }),
      button("Add todo", {
        onclick() {
          addTodo(
            referenceSet.elem<HTMLInputElement>("todoInput")!.value || ""
          );
          referenceSet.elem<HTMLInputElement>("todoInput")!.value = "";
        },
      })
    ),
    todoList
  );
}

const todoList =  function () {
  const data = this.pipes.get("todo");
  return div(
    data.map((item: any) =>
      p(item, {
        title: "click to remove",
        onclick() {
          removeTodo(item);
        },
      })
    )
  );
};
document.body.appendChild(TodoList());

working with page and Router

Unlike just appending stuff to the DOM, a better to build apps is to use a routing system.

Cradova Router is a module that allows you do the following:

Create specified routes in you application help you handle navigation render a page on a route listen to Navigation changes create error boundary at page level apart from Function level.

let's try an example.

import { Page, Router, useEffect } from "cradova";

const home = new Page({
  name: "home page", // page title
  template: () => div(template),
});

// in your routes.ts file
Router.BrowserRoutes({
  // Ways to use paths and Pages
  "*": home,
  "/home": home,
  "/home?": home,
  "/home/:name": home,
  // will be lazy loaded
  "/lazy-loaded-home": async () => await import("./home"),
});
// creates these routes

Router.navigate("/home", data);
// navigates to that page

Router.onPageEvent((lastRoute, newRoute) => {
  console.log(lastRoute, newRoute);
});
// listen for navigation changes

More info


More info on Cradova Router


Every Cradova app mounts on a div with attribute data-wrapper="app"

if it already exist Cradova will use it instead.

Cradova will create a div with data-wrapper="app" if it doesn't exists already.

so if you want to use your own mount point then create a div with data-wrapper="app".


More info on Cradova pages


Cradova pages has onActivate() and onDeactivate() methods which is also available in the component function on the this variable bound to it.

this allow you manage rendering circle for each page in your app


More info on Cradova Function


Cradova Function is a dynamic component class, which ships simple abstractions like:

  • Signal
  • useEffect
  • useState
  • useRef
  • preRender

these behaviors allow you manage rendering circle for Functions in your app


More info on Cradova createSignal


Cradova Signals allows you to create powerful data stores.

with ability to:

  • create store
  • create actions and fire them
  • bind a Function
  • listen to changes
  • persist changes to localStorage

With these simple and easy abstractions, you can write datastores with so much convenience.

Documentation

At the moment, we're in the process of creating a documentation website for Cradova, and we have limited resources. If you're interested in lending a hand, we invite you to join our community, gain firsthand experience, and contribute to the advancement of Cradova.

Getting Help

To get further insights and help on Cradova, visit the Discord and Telegram Community Chats.

Contributing

We are currently working to set up the following:

  • building Cradova CLI (in progress)
  • Cradova Documentation Website
  • Sample projects
  • maintenance and promotion
 ██████╗   ██████╗    █████═╗   ███████╗    ███████╗    ██╗   ██╗  █████╗
██╔════╝   ██╔══██╗  ██╔═╗██║   █      ██  ██╔═════╝█   ██║   ██║  ██╔═╗██
██║        ██████╔╝  ███████║   █      ██  ██║     ██   ██║   ██║  ██████╗
██║        ██╔══██╗  ██║  ██║   █      ██  ██║     ██   ╚██╗ ██╔╝  ██║  ██╗
╚██████╗   ██║  ██║  ██║  ██║   ███████╔╝   ████████      ╚███╔╝   ██║  ██║
 ╚═════╝   ╚═╝  ╚═╝  ╚═╝  ╚═╝   ╚══════╝     ╚════╝        ╚══╝    ╚═╝  ╚═╝

MIT Licensed

Open sourced And Free.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under same license. You are also implicitly verifying that all code is your original work.

Supporting Cradova development

Your Support is a good force for change anytime you do it, you can ensure Our projects, growth, Cradova, Cradova, JetPath etc, growth and improvement by making a re-occurring or fixed sponsorship to github sponsors:

Support via cryptos -

  • BTC: bc1q228fnx44ha9y5lvtku70pjgaeh2jj3f867nwye
  • ETH: 0xd067560fDed3B1f3244d460d5E3011BC42C4E5d7
  • LTC: ltc1quvc04rpmsurvss6ll54fvdgyh95p5kf74wppa6
  • TRX: THag6WuG4EoiB911ce9ELgN3p7DibtS6vP

Build Powerful ⚡ Web Apps with Ease.

changelog

cradova changelog

v1.0.0

  • basic functionality no proper way to handle state

v1.0.1

  • improved performance

v1.0.2

  • improved api and dev experience

v1.0.3

  • an improved state management

v1.0.4

this version never existed "npm version patch" was mistakenly entered twice and we went along with it.

v1.0.5

  • more performance
  • improved state management
  • battle testing and production readiness

v1.0.6

  • introducing scaffold - a simple way to render page components without url manipulation. this brings app experience
  • bug fixes
  • more performance
  • battle testing green

v1.0.7

  • bug fixes
  • more performance
  • battle testing green

v1.0.8

  • bug fixes
  • more performance
  • battle testing green

v1.0.1

  • bug fixes
  • battle testing green

v1.1.0

  • all bugs fixes
  • great performance gain
  • battle testing green
  • dripping build system
  • stable type system

v1.2.0

  • bugs fixes
  • new performance gain unlocked
  • battle testing green
  • new apis for element level
  • fixed all know abnormal behaviors

v1.3.0

  • new very feature to unlock more speed
  • battle testing green
  • new apis at element level

v1.4.0

  • unlocked more speed by reducing work done by router
  • battle testing green
  • added error boundary
  • Comp working as wanted

v1.4.1

  • fix effect on cradova pages

v1.5.0

  • made cradova Comp to have Stash hold component state change
  • stable Comp effect and recall compliant to the spec

v2.0.0

  • export all html tags prebuilt and fully typed for more performance
  • removed effect and recall from cradova page class
  • remove unnecessary useHistory option from createSignal
  • removed ability to add styles that appears as normal props
  • removed event object from router params
  • added pre-rendering capability to Comp components
  • fixed effect bug on Comp
  • added assert to cradova elements
  • fixed error boundary bug
  • setup hybrid server side rendering test using vite ssr

v2.1.0

  • added loop
  • allow custom mount point
  • fixed data-prop attributes
  • fixed type for pages
  • writing tests for more speed improvement index
  • fixed createAction callback type

v2.1.1

  • increased child dept to ~

v2.1.2

  • fixed child array recursion of the Rhoda function
  • fixed types
  • fixed errors on child type not caught by typescript

v2.2.0

  • big performance boost using new methods of handling function calls so they get cached
  • added lazy loading to cradova routes
  • fixed Comp state flow with tests in ./manual_tests
  • added the lazy class to load components when needed
  • added parallel rendering to cradova pages
  • redefining what global dispatcher can do.
  • fix routing bug
  • fix page not persisting bug
  • proof tests
  • battle testing used and tested in production

v2.2.1

  • fix some little bugs

v2.2.2

  • make tag parser faster and fixed a tiny bug
  • completed various tests

v2.2.3

  • make tag parser faster and fixed a tiny bug
  • completed various tests

v2.3.0

  • created CradovaEvent switched from the CustomEvent class (for more speed and node compatibility journey)
  • created references as a way to point to dom elements
  • used reference internally to remove cradova-ids that appeared on the dom before.
  • completed tests
  • cradova now helps you with Comp.render() calls
  • Comp can be used as pages directly

v2.3.1

  • fixes and more stability

v3.0.0

  • Redefined types
  • removed afterMount and beforeMount events from cradova elements
  • added the onmount event that get's called when the page tree or comp get's updated
  • disabled the global dispatcher because it's no longer a need for reactivity
  • production tests
  • the cradova _ function now has types
  • fixes and more speed gain for your apps when you update cradova.
  • added a solution for setting a loading page
  • production tests for parallel rendering completed

v3.1.1

  • Added useState, useEffect and useRef hooks
  • did some more optimization
  • other changes

v3.1.4

  • fixed bug parallel rendering in comp by managing page id events making them more powerful by also now reactivity to page changes
  • other optimizations in pre-rendering

v3.2.0

  • introduced a more standardized reference class for managing dom references update the previous implementations.
  • fixed more bug parallel rendering in comp by managing page id events making them more powerful by also now reactivity to page changes
  • other optimizations in pre-rendering

v3.3.0

  • introduced Comp.define construct to add custom methods to Comps
  • introduced more refined conditional rendering of $switch & $case, $if and $ifelse.
  • introduced active option in Comps to fine tune multi-rendered Comps mostly in parallel rendered situations, hence further making parallel rendering more stable and rock solid with this new feature.
  • tested in production across several personal projects and did some custom testing
  • introduced the raw tag, just put in raw html strings if you need to for static contents/makeup, better for seo and faster render of none-dynamic contents.

v3.3.1

  • fixed speed, types, improvements and the define method

v3.4.0

  • fixed type system, removed templating more performance, fixed performance in routing system, pages, and comp
  • more standard and speed.

v3.5.8

  • fixed type system, fixed performance in routing system, pages, and comp
  • more standard and more speed.

v3.6.0

  • removed Comp or Ref classes
  • Implemented a system to use function as functional components

v3.7.0

  • Implemented signal.pass for binding signal event to specific elements in th a function, a way to self handle reactivity and avoid complex diffing algorithms,

v3.8.0

  • Implemented more hooks and a syntax upgrades.

3.8.0-rc-1

  • Implemented Store class for binding signal event to Immutable objects.
  • Implemented signals.pass for binding signal event to specific elements in the a function.
  • Implemented signals.listen for binding signal event to listeners.

3.8.0-rc-2 & 3.8.0-rc-3

  • Removed Comp.signals and .pipes; to enforces Signal instances to be used only on global scope as a global state manager.

v3.8.0-rc-4

  • Implemented virtual list

v3.11.0

  • Improved Signals, API changes.

v3.11.7

  • Implemented useExternalEffect for external effects to a Comp instance

v3.11.9

  • Implemented args to Comp component._args

v3.12.0

  • Discharged this feature to allow more flexibility in the way you use args

v3.12.1

  • added and fixed silentStore property for cradova signals.

v3.12.2

  • Bug fixes in cradova pages
  • snapshot isolation is removed due to security issues.