0.0.131 • Published 11 months ago

cuppajs v0.0.131

Weekly downloads
296
License
MIT
Repository
github
Last release
11 months ago

CuppaJS - Standard libraries that work with everything out there.

A set of libraries to create any kind of javascript projects but regardless to other libraries, it is focus in vanilla javascript giving standard tools to built code and reuse it anywere, not matter the toolset (reactj, angular, vue, svelte).

There are tons of good frameworks and libraries implementations out there to create amazing projects and one of the biggest problems is found solid mature standard resources that works with alls of them, for example: if you are using Angular the way to go is found an Angular Component that solve your needed, but if you need switch or create a new project using other technology base "React", needs to found an alternative that supply your needs in that specific framework.

CuppaComponent.js | CuppaRouter.js | CuppaStorage.js

Advantages

  • Compatible with any other framework or libraries due is just standard code.
  • Faster performance thanks to lit-html a simple, modern and fast HTML templeating.
  • No pre-compilation process.
  • Small size.
  • No dependencies.

Documentation

Doc http://cuppajs.cloudbit.co/ Git https://github.com/cloudbit-interactive/cuppajs Npm https://www.npmjs.com/package/cuppajs WebComponents https://www.webcomponents.org/element/cuppajs-elements

Cuppa Component ~5.5kB gzipped

// Load or embed the library
import {CuppaComponent, html} from "https://cdn.jsdelivr.net/npm/cuppajs/libs/cuppa.component.min.js";

export default class MyComponent extends CuppaComponent {
    count = this.observable("count", 0);
    refs = {myDivRef:null};

    constructor(){ super(); }

    // Standard webComponent to observe attributes
    static get observedAttributes() { return ['attr1', 'attr2'] }
    attributeChangedCallback(attr, oldVal, newVal) { this[attr] = newVal }
    
    // Invoked when the custom element is first connected to the document's DOM.
    mounted() { }   
    
    // Invoked when the custom element is disconnected from the document's DOM.
    unmounted() { }
  
    // Invoked after render execution
    rendered(){ }             
   
    render(){
        return html`
            <div ref="myDivRef">    
                <button @click=${ ()=>this.count-- }>+</button>
                <span>Count: ${this.count}</span>
                <button @click=${ ()=>this.count++ }>+</button>
            </div>`
    }
}

// Standard way to defines a new custom element.
customElements.define('my-component', MyComponent);

// Ok, now we can add a instance of our component and see the result
document.body.append(new MyComponent())

Cuppa Router ~2.5kB gzipped

// Load or embed the library
import { CuppaRouter } from "https://cdn.jsdelivr.net/npm/cuppajs/libs/cuppa.router.min.js";

const router = new CuppaRouter();
router.addListener(onRouterUpdated);
router.updateLinks();
router.resolve();

function  onRouterUpdated(path)  {
	let content = document.getElementById("content");
	content.innerHTML =  "";
		
	if(router.match(path,  "/"))  {
		content.innerHTML = "Home Page";
	}else if(router.match(path, "works"))  {
		content.innerHTML = "Works";
	}else if(router.match(path, "works/:alias"))  {
		let data = router.match(path, "works/:alias");
		content.innerHTML = `<strong>Work Alias:</strong> ${data.params.alias}`;
	}
}

Cuppa Storage ~2.0kB gzipped

// Load or embed the cuppa.component.js library
import {CuppaStorage} from "https://cdn.jsdelivr.net/npm/cuppajs/libs/cuppa.storage.min.js";

// Register a callback that will be automatically updated when value change
// store = null, LOCAL, SESSION, INDEXED_DB
CuppaStorage.getData({name:"user", store:CuppaStorage.LOCAL, defaultValue:null, callback:(data)=>{
    console.log(data);
}})

// Set the value in the storage
CuppaStorage.setData({name:"user", data:{name:"Tufik", age:36}, store:CuppaStorage.LOCAL});

// Also is possible ge the value directly.
let value = await CuppaStorage.getData({name:"user", store:CuppaStorage.LOCAL, defaultValue:null});
// CuppaStorage.getDataSync doesn't support store CuppaStorage.INDEXED_DB due IndexedDB is async
let value = CuppaStorage.getDataSync({name:"user", store:CuppaStorage.LOCAL});
0.0.128

12 months ago

0.0.131

11 months ago

0.0.130

12 months ago

0.0.127

1 year ago

0.0.126

1 year ago

0.0.125

1 year ago

0.0.124

1 year ago

0.0.123

1 year ago

0.0.117

1 year ago

0.0.119

1 year ago

0.0.118

1 year ago

0.0.120

1 year ago

0.0.122

1 year ago

0.0.116

1 year ago

0.0.115

1 year ago

0.0.114

2 years ago

0.0.113

2 years ago

0.0.112

2 years ago

0.0.111

2 years ago

0.0.110

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.106

2 years ago

0.0.107

2 years ago

0.0.95

2 years ago

0.0.105

2 years ago

0.0.96

2 years ago

0.0.104

2 years ago

0.0.97

2 years ago

0.0.103

2 years ago

0.0.98

2 years ago

0.0.101

2 years ago

0.0.100

2 years ago

0.0.91

2 years ago

0.0.92

2 years ago

0.0.93

2 years ago

0.0.94

2 years ago

0.0.88

3 years ago

0.0.89

3 years ago

0.0.90

3 years ago

0.0.87

3 years ago

0.0.86

3 years ago

0.0.85

3 years ago

0.0.84

3 years ago

0.0.83

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.80

3 years ago

0.0.76

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.75

3 years ago

0.0.73

3 years ago

0.0.74

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.69

3 years ago

0.0.70

3 years ago

0.0.68

3 years ago

0.0.67

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.62

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.58

3 years ago

0.0.57

3 years ago

0.0.56

3 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.52

3 years ago

0.0.53

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.44

3 years ago

0.0.46

3 years ago

0.0.48

3 years ago

0.0.43

3 years ago

0.0.42

3 years ago

0.0.41

3 years ago