0.0.68-h • Published 1 year ago

curvature v0.0.68-h

Weekly downloads
224
License
Apache-2.0
Repository
github
Last release
1 year ago

avatar

Curvature.js

v.0.0.68

curvature Apache-2.0 Licence Badge Size badge

CircleCI

Curvature is a lightweight javascript framework with an emphasis on straightforwardness.

This document serves only as an overview. For more in-depth, interactive documentation, see http://curvature.seanmorr.is/.

Getting started

Install with npm:

$ npm install curvature

Creating Views

Create a view class:

import { View } from 'curvature/base/View';

class MyView extends View
{
	constructor()
	{
		super();

		this.template = `<b>Hello, world!</b>`;
	}
}

or an anonymous view:

import { View } from 'curvature/base/View';

const view = View.from(`<b>Hello, world!</b>`);

Render a view directly into an existing tag:

import { View } from 'curvature/base/View';

const view = View.from(`<b>Hello, world!</b>`);
const div  = document.querySelector('div.hello');

view.render(div);

Render a view to the <body> tag as soon as the DOM is ready:

import { View } from 'curvature/base/View';

const view = View.from(`<b>Hello, world!</b>`);

document.addEventListener('DOMContentLoaded', () => {
	const body = document.querySelector('body');
	view.render(body.element);
});

Separating Templates

Writing HTML into a javascript string can be annoying.

Use the rawquire babel macro to import templates directly from html files, and maintin your syntax highlighting.

$ npm install rawquire

my-template.html:

<p>This is my template!</p>

MyView.js:

import { rawquire } from 'rawquire/rawquire.macro';
import { View } from 'curvature/base/View';

class MyView extends View
{
	constructor()
	{
		super();

		this.template = rawquire('./my-template.html');
	}
}

Variable Binding

Use the cv-bind attribute, or [[squarebrackets]] to insert variables from the view.args property into your templates:

my-template.html

<p><span cv-bind = "prefix"></span> [[time]]</p>

MyView.js

import { rawquire } from 'rawquire/rawquire.macro';
import { View } from 'curvature/base/View';

class MyView extends View
{
	constructor()
	{
		super();

		this.args.prefix = 'The time is';

		this.onInterval(1, ()=>{
			this.args.time = Date.now();
		});

		this.template = rawquire('my-template.html');
	}
}

Event Listeners

Use the cv-on attribute to listen for events on your view object:

clickable.html

<button cv-on = "click:click(event)">click me!</button>

Clickable.js

import { rawquire } from 'rawquire/rawquire.macro';
import { View } from 'curvature/base/View';

class Clickable extends View
{
	constructor()
	{
		super();

		this.template = rawquire('./clickable.html');
	}

	click(event)
	{
		alert('button clicked!');
	}
}

Or, for anonymous views:

import { View } from 'curvature/base/View';

const view = View.from(`<button cv-on = "click:click(event)">click me!</button>`);

view.click = (event) => {
	alert('button clicked!');
};

If the event & method names match, you can just specify it once.

import { View } from 'curvature/base/View';

const view = View.from(`<button cv-on = "click(event)">click me!</button>`);

view.click = (event) => {
	alert('button clicked!');
};

Multiple listeners may be provided in a ";" separated list:

import { View } from 'curvature/base/View';

const view = View.from(`<button cv-on = "click(event);hover(event)">click me!</button>`);

view.click = (event) => {
	alert('button clicked!');
};

view.hover = (event) => {
	console.log('button hovered!');
};
0.0.68-h

1 year ago

0.0.68-g

2 years ago

0.0.68-e

2 years ago

0.0.68-f

2 years ago

0.0.68-c

2 years ago

0.0.68-d

2 years ago

0.0.68-a

2 years ago

0.0.68-b

2 years ago

0.0.67-b

2 years ago

0.0.67-c

2 years ago

0.0.67-a

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.66-r

3 years ago

0.0.66-p

3 years ago

0.0.66-q

3 years ago

0.0.66-o

3 years ago

0.0.66-n

3 years ago

0.0.66-m

3 years ago

0.0.66-l

3 years ago

0.0.66-k

3 years ago

0.0.66-j

3 years ago

0.0.66-i

3 years ago

0.0.66-h

3 years ago

0.0.66-g

3 years ago

0.0.66-f

3 years ago

0.0.66-e

3 years ago

0.0.66-d

3 years ago

0.0.66-c

3 years ago

0.0.66-b

3 years ago

0.0.66-a

4 years ago

0.0.66

4 years ago

0.0.65

4 years ago

0.0.63

4 years ago

0.0.62

4 years ago

0.0.61

4 years ago

0.0.60

4 years ago

0.0.59

4 years ago

0.0.58

4 years ago

0.0.57

4 years ago

0.0.56

4 years ago

0.0.55

4 years ago

0.0.54-c

4 years ago

0.0.54-b

4 years ago

0.0.54-a

4 years ago

0.0.54

4 years ago

0.0.53

4 years ago

0.0.51

4 years ago

0.0.52

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.48

4 years ago

0.0.47

4 years ago

0.0.46

4 years ago

0.0.45

4 years ago

0.0.44

4 years ago

0.0.43

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4-a

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago