0.0.37 • Published 5 years ago

vue-object v0.0.37

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

Gitpod Ready-to-Code

vue-object

Treat normal objects as vue components.

This library allows you to create an application using a plain objects that can render themselves. Perfect to proper encapsulation and widgets library. No external dependencies, works with vue as a rendering platform. See tests

Install:

npm install vue-object

Then add custom renderer and configure tsx

/// main.ts

import { Renderer } from 'vue-object';
Vue.use(Renderer);
/// shims-tsx.d.ts

import Vue, { VNode } from 'vue'

declare global {
  namespace JSX {
    // tslint:disable no-empty-interface
    interface Element { } // for now disable all type checks
    // tslint:disable no-empty-interface
    interface ElementClass { }
    interface IntrinsicElements {
      [elem: string]: any
    }
  }
}

And use plain classes instead of components

/// About.tsx

import { prop, event, slot, Handler } from "vue-object"

class Panel {
  slot: any;

  render() {
    return <div>
      Panel start
      {this.slot}
      Panel end
    </div>
  }
}

class Text {
  constructor(private text: string) {

  }
  render() {
    return <span> {this.text}</span>
  }
}

export class About {

  panel = new Panel();

  constructor() {
    // pass plain objects, that can render themselves
    this.panel.slot = new Text("Object content");
  }

  render(h: any) {
    return <div>
      <Panel>
        jsx panel content
        </Panel>
      {this.panel}
    </div>
  }
}

You can always convert classes to vue components using Convert utility. For example for VueRouter:

/// router.ts

import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import { Home } from '../views/Home'
import { About } from '../views/About'
import { Convert } from 'vue-object'

const routes: Array<RouteConfig> = [
  {
    path: '/',
    name: 'Home',
    component: Convert(Home)
  },
  {
    path: '/about',
    name: 'About',
    component: Convert(About)
  }
]
0.0.37

5 years ago

0.0.36

5 years ago

0.0.32

5 years ago

0.0.33

5 years ago

0.0.34

5 years ago

0.0.35

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.28

5 years ago

0.0.29

5 years ago

0.0.27

5 years ago

0.0.20

5 years ago

0.0.21

5 years ago

0.0.22

5 years ago

0.0.23

5 years ago

0.0.24

5 years ago

0.0.25

5 years ago

0.0.16

5 years ago

0.0.17

5 years ago

0.0.18

5 years ago

0.0.19

5 years ago

0.0.26

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.11

5 years ago

0.0.12

5 years ago

0.0.13

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

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.1

5 years ago