0.6.7 ā€¢ Published 5 years ago

@authman2/mosaic v0.6.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Mosaic

Mosaic is a declarative front-end JavaScript library for building user interfaces!

šŸ’  (Web) Component-Based: Mosaic uses the Custom Elements API to create web components that can keep track of their own data, actions, and more, and can be included in other components to create single page applications.

āš”ļø Observable Data: Mosaic uses Observables to keep track of changes to a component's data. This means that there is no need to call "setState" or anything like that to update a component - instead just change the data directly.

šŸ§  Smart DOM: Updates in Mosaic work by remembering which nodes are dynamic (i.e. subject to change) and traveling directly to those nodes to make changes, rather than traversing the tree again.

šŸ”€ Built-in Router: Comes with a basic, client-side router which allows Mosaic components to be used as separate pages.

šŸŒ State Manager: Comes with a built-in global state manager called Portfolio.

šŸ‘Œ Small Library Size: The minified Mosaic library comes in at a size of 22KB.

šŸ”– Tagged Template Literals: Views are written using tagged template literals, which means there is no need for a compiler:

const name = "Mosaic";
html`<h1>Welcome to ${name}!</h1>`

Demo

Here is an example of a simple Mosaic application. All you need is an index.html file and an index.js file. For a more detailed example, run the project inside the "example" folder.

index.html:

<html>
  <head>
    <title>My Mosaic App</title>
  </head>
    
  <div id='root'></div>

  <script src='https://unpkg.com/@authman2/mosaic@latest/dist/index.js'></script>
  <script type="text/javascript" src='./index.js'></script>
</html>

index.js:

// Import Mosaic
import Mosaic from '@authman2/mosaic';

// The "text" data property gets injected by 
// the parent component so we need to specify
// that in the "data" option with a default value.
new Mosaic({
    name: 'my-label',
    data: { text: '' },
    view: self => {
        return html`
            <h2>${ self.data.text }</h2>
            <p>This is a custom label component!</p>
            ${self.descendants}
        `;
    }
});

// Create an app component. Note how components
// do not need to be nested under a single div.
const app = new Mosaic({
    name: 'my-app',
    element: 'root',
    data: { title: "Mosaic App" },
    sayHello: function() {
        console.log("Hello World!!");
        console.log("This component is ", this);
    },
    view: function() {
        return html`
            <h1>This is a ${this.data.title}!</h1>
            <p>Click below to print a message!</p>
            <button onclick="${this.sayHello}">Click Me!</button>

            <my-label text='Welcome to Mosaic!'>
                Awesome, right?
            </my-label>
        `;
    }
});

// Paint the Mosaic onto the page.
app.paint();

Installation

The easiest way to use Mosaic is to first install the npm package by using:

npm install --save @authman2/mosaic

or with a script tag.

<script src='https://unpkg.com/@authman2/mosaic@latest/dist/index.js'></script>

(Optional) For fast builds and hot reloading, install the build tool "Parcel." This is not required, though, as Mosaic uses built-in JavaScript features. This means that no build tool is required, but any may be used if it helps the overall project structure.

npm install --save-dev parcel-bundler

Now you are ready to use Mosaic!

Author

  • Year: 2019
  • Programmer: Adeola Uthman
  • Languages/Tools: JavaScript, TypeScript, Parcel
0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.13

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5999

5 years ago

0.4.595

5 years ago

0.4.59

5 years ago

0.4.5

5 years ago

0.4.468

5 years ago

0.4.467

5 years ago

0.4.466

5 years ago

0.4.46555

5 years ago

0.4.4655

5 years ago

0.4.465

5 years ago

0.4.46

5 years ago

0.4.45995

5 years ago

0.4.4599

5 years ago

0.4.4598

5 years ago

0.4.4597

5 years ago

0.4.4596

5 years ago

0.4.4595

5 years ago

0.4.4594

5 years ago

0.4.4593

5 years ago

0.4.4592

5 years ago

0.4.4591

5 years ago

0.4.459

5 years ago

0.4.458

5 years ago

0.4.457

5 years ago

0.4.456

5 years ago

0.4.45

5 years ago

0.4.44

5 years ago

0.4.431

5 years ago

0.4.43

5 years ago

0.4.42

5 years ago

0.4.41

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.94

5 years ago

0.1.93

5 years ago

0.1.92

5 years ago

0.1.91

5 years ago

0.1.9

5 years ago

0.1.82

5 years ago

0.1.81

5 years ago

0.1.8

5 years ago

0.1.79

5 years ago

0.1.78

5 years ago

0.1.77

5 years ago

0.1.76

5 years ago

0.1.75

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.151

5 years ago

0.0.15

5 years ago

0.0.146

5 years ago

0.0.145

5 years ago

0.0.14

5 years ago

0.0.135

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.1

5 years ago

1.0.0

5 years ago