0.0.37 • Published 4 years ago

vue-object v0.0.37

Weekly downloads
2
License
MIT
Repository
github
Last release
4 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

4 years ago

0.0.36

4 years ago

0.0.32

4 years ago

0.0.33

4 years ago

0.0.34

4 years ago

0.0.35

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.28

4 years ago

0.0.29

4 years ago

0.0.27

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.26

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago