0.0.68-h • Published 2 years ago

curvature v0.0.68-h

Weekly downloads
224
License
Apache-2.0
Repository
github
Last release
2 years 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

2 years ago

0.0.68-g

3 years ago

0.0.68-e

3 years ago

0.0.68-f

3 years ago

0.0.68-c

3 years ago

0.0.68-d

3 years ago

0.0.68-a

3 years ago

0.0.68-b

3 years ago

0.0.67-b

4 years ago

0.0.67-c

4 years ago

0.0.67-a

4 years ago

0.0.67

4 years ago

0.0.68

4 years ago

0.0.66-r

4 years ago

0.0.66-p

4 years ago

0.0.66-q

4 years ago

0.0.66-o

4 years ago

0.0.66-n

4 years ago

0.0.66-m

4 years ago

0.0.66-l

4 years ago

0.0.66-k

5 years ago

0.0.66-j

5 years ago

0.0.66-i

5 years ago

0.0.66-h

5 years ago

0.0.66-g

5 years ago

0.0.66-f

5 years ago

0.0.66-e

5 years ago

0.0.66-d

5 years ago

0.0.66-c

5 years ago

0.0.66-b

5 years ago

0.0.66-a

5 years ago

0.0.66

5 years ago

0.0.65

5 years ago

0.0.63

5 years ago

0.0.62

5 years ago

0.0.61

5 years ago

0.0.60

5 years ago

0.0.59

5 years ago

0.0.58

5 years ago

0.0.57

5 years ago

0.0.56

5 years ago

0.0.55

5 years ago

0.0.54-c

5 years ago

0.0.54-b

5 years ago

0.0.54-a

5 years ago

0.0.54

5 years ago

0.0.53

5 years ago

0.0.51

5 years ago

0.0.52

5 years ago

0.0.50

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4-a

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago