• This repository has been archived on 05/Aug/2020
  • Stars
    star
    205
  • Rank 185,160 (Top 4 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ’« A complete solution to building modern webs with Vue.js and its friends.




eva.js is a complete solution to
building modern webs with Vue.js.

NPM version NPM downloads david dm

tl;dr

// model
app.model()
// router
app.router()
// bootstrap
app.start()

Play with the JSBin example or the simple webpack example πŸ˜€

Table of Contents

Sites using eva.js

Feel free to add your project here!

Features

  • Battery included, Vue 2 and its friends (Vuex & Vue-Router)
  • Small APIs, just Vue and the official plugins you already play well with!
  • Support server-side rendering, of course!
  • Inspired by the choo framework which is inpired by the elm architecture

Install

$ npm install --save eva.js

In case you may want to use it directly in browser instead, view https://unpkg.com/eva.js/dist/, and add:

<!-- global variable `EVA` is available as a constructor(class) -->
<!-- note that, you should use new EVA.default() to create app instance in browser -->
<script src="/path/to/eva.js"></script>

If you use the commonjs version and wanna include the runtime for vue template, follow the official guide:

Usage

import EVA from 'eva.js'

// Create app instance
const app = new EVA()

// A counter model
app.model({
  state: {count: 0},
  mutations: {
    INCREMENT(state) {state.count++}
  }
})

// A home view
const Home = {
  computed: {
    count() {
      return this.$store.state.count
    }
  },
  render(h) {
    return (
      <div>
        <h1>Home</h1>
        <button on-click={() => this.$store.commit('INCREMENT')}>
          {this.count}
        </button>
      </div>
    )
  }
}

// Apply views to relevant routes
// route(path, view, child_routes)
app.router(route => [
  route('/', Home)
])

// Start app
const App = {
  render(h) {
    return (
      <div id="app">
        <router-view></router-view>
      </div>
    )
  }
}
app.start(App, '#app')
// equal to
// app.start(App)
// app.mount('#app')

Concepts

Models

A model contains it's initial state and the methods you use to update its state, in fact, it's a typical Vuex module too.

Top-level model:

// An app instance only have at most one top-level model
app.model({
  state: {count: 0},
  mutations: {
    INCREMENT(state) {state.count++}
  }
})

Named/Namespaced model:

// An app could have multiple named models
app.model({
  name: 'user',
  state: {login: false},
  mutations: {
    LOG_IN(state) {state.login = true}
  }
})

By default only state are registered locally under provided name, eg state.user.login. But mutations actions getters are still in global namespace, to enforce name for those too, please change name to namespace:

app.model({
  namespace: 'user',
  state: {login: false},
  mutations: {
    LOG_IN(state) {state.login = true}
  },
  actions: {
    login({commit}) {
      commit('LOG_IN') //=> user/LOG_IN
    }
  }
})

Check out official docs for modules in vuex: http://vuex.vuejs.org/en/modules.html

In most cases using namespaces is beneficial, as having clear boundaries makes it easier to follow logic.

Helpers:

As how you use Vuex^2, you can use its helpers too:

const {mapState, mapActions, mapGetters} = require('eva.js')
// or ES6 modules
import {mapState, mapActions, mapGetters} from 'eva.js'

// of course you can directly import from 'vuex' too
import {mapState, mapActions, mapGetters} from 'vuex'

Router

The router could render the component which matches the URL path. It has a route helper for creating an actual route object used in vue-router. routes are passed in as a nested array.

app.router(route => [
  route('/', Home),
  route('/settings', Settings, [
    route('/profile', SettingsProfile),
    route('/password', SettingsPassword)
  ])
])

// use an object as route argument:
route({path: '/', component: Home, /*...*/})

// use an object as router argument:
app.router({
  mode: 'history',
  routes: []
})

The router state is effortlessly synced in vuex store.

Views

A view is a simple Vue component, that easy :)

Vue constructor

If you wan to access Vue constructor directly, simply do:

import {Vue} from 'eva.js'
// or without any change
// import Vue from 'vue'
// works too

Vue.use(yourPlugin)

Access $store and $router outside component

You can initialize your app and bootstrap it later:

// ./src/app.js
import EVA from 'eva.js'

const app = new EVA()

app.model() //...
app.router() //...

export default app.start()

// ./src/index.js
import app from './app'
app.mount('#app')

// ./some/other/file.js
import app from './path/to/src/app.js'

app.$router.push('/somewhere')

Server-side rendering

Similar to the official hackernews example:

// ./src/app.js
import EVA from 'eva.js'
import App from './App.vue'

const app = new EVA()

export default app.start(App)
// without selector!
// otherwise it will be mounted to the selector

Then for the server-entry.js:

// ./src/server-entry.js
import app from './app'

export default context => {
  // you can access app.$router / app.$store
  return Promise.all(operations)
    .then(() => {
      return app.instance
    })
}

For client-entry.js:

import app from './app'

app.mount('#app')

Promise polyfill

Some browsers do not have native Promise, like IE, but vuex requires Promise. Thus eva.js provides an lightweight Promise polyfill with promise-polyfill.

import 'eva.js/promise-polyfill'
import EVA from 'eva.js'
// ... your app code

API

new EVA([options: object])

Create an app instance.

options.mode

The router mode, can be either hash (default) or history.

app.model(model: object)

Register a model, a.k.a. store module in Vuex. You can omit the name and namespace property to make it top-level.

app.router(handler: function)

Register routes.

app.use(plugin: function, [options: object])

The same as Vue.use, you can apply any Vue plugin.

app.start([App: object], [selector: string])

Create app instance. Optionally mount App component to a domNode if selector is defined.

If App is not specified, we use a default value:

const defaultApp = {
  render(h) {
    return <div id="app"><router-view></router-view></div>
  }
}

If selector is not specified, we won't mount the app instance to dom.

app.mount(selector)

Mounted app instance to dom, must be call after app.start([App]) (without selector argument). Default selector is #app

app.syncRouterInStore()

keep vue-router and vuex store in sync, i.e. keep router state in vuex store.

The method will be called automatically in app.start(), you can also call it manually before app.start() and app.start() won't call it again.

app.$store

The vuex store instance.

app.$router

The vue-router instance.

app.instance

The Vue instance created by app.start(), most likely you will use this in server-side rendering.

Development

# build and watch source files
$ npm run watch

# launch server for simple html example
$ http-server .
# run webpack example
$ npm run webpack

# build for publish to npm
# cjs and umd and compressed umd
$ npm run build

License

MIT Β© EGOIST

More Repositories

1

tsup

The simplest and fastest way to bundle your TypeScript libraries.
TypeScript
5,588
star
2

poi

⚑A zero-config bundler for JavaScript applications.
JavaScript
5,243
star
3

docute

πŸ“š Effortless documentation, done right.
JavaScript
3,725
star
4

devdocs-desktop

πŸ—‚ A full-featured desktop app for DevDocs.io.
JavaScript
3,132
star
5

vue-content-loader

SVG component to create placeholder loading, like Facebook cards loading.
JavaScript
3,025
star
6

hack

β›· Dead simple CSS framework.
CSS
2,587
star
7

vuepack

πŸ“¦ A modern starter which uses Vue 2, Vuex, Vue-router and Webpack 2 (and even Electron)
JavaScript
2,438
star
8

eme

Elegant Markdown Editor.
JavaScript
2,045
star
9

maid

Markdown driven task runner.
JavaScript
2,006
star
10

dum

An npm scripts runner written in Rust.
Rust
1,422
star
11

import-http

Import modules from URL instead of local node_modules
JavaScript
1,239
star
12

codepan

Like codepen and jsbin but works offline.
JavaScript
1,119
star
13

bili

Bili makes it easier to bundle JavaScript libraries.
TypeScript
1,047
star
14

esbuild-register

Transpile JSX, TypeScript and esnext features on the fly with esbuild
TypeScript
912
star
15

tailwindcss-icons

Use any icon (100,000+) from Iconify, for TailwindCSS
TypeScript
774
star
16

vue-timeago

A timeago component for Vue.
JavaScript
734
star
17

docup

The easiest way to write beautiful docs.
TypeScript
707
star
18

dropcode

A simple and lightweight code snippet manager.
TypeScript
676
star
19

rollup-plugin-postcss

Seamless integration between Rollup and PostCSS.
JavaScript
674
star
20

vue-monaco

MonacoEditor component for Vue.js
JavaScript
651
star
21

vue-feather-icons

Simply beautiful open source icons as Vue functional components.
Vue
586
star
22

rollup-plugin-esbuild

Use ESBuild with Rollup to transform ESNext and TypeScript code.
TypeScript
566
star
23

vue-mugen-scroll

Infinite scroll component for Vue.js 2
JavaScript
546
star
24

vue-client-only

Vue component to wrap non SSR friendly components (428 bytes)
JavaScript
473
star
25

biu

🚨 An alert replacement
HTML
442
star
26

styled-vue

Use dynamic styles in Vue single-file components.
JavaScript
428
star
27

package-size

Get the bundle size of an npm package.
JavaScript
422
star
28

tooling

Modular JavaScript Tooling.
JavaScript
417
star
29

vue-router-prefetch

Prefetch links when they are visible in viewport.
JavaScript
383
star
30

node-vs-deno

A Deno guide for Node.js developers
363
star
31

presite

A static site generator based on Puppeteer.
TypeScript
331
star
32

esmon

like nodemon but very esbuild.
TypeScript
324
star
33

franxx

A vanilla JavaScript router that works everywhere.
TypeScript
321
star
34

ts-lib-starter

My minimal TypeScript library starter
TypeScript
269
star
35

vue-final-form

🏁 High performance subscription-based form state management for Vue.js.
Vue
265
star
36

hanabi

πŸ’₯ Highlight any code, in a colorful way. (seriously 700 bytes)
JavaScript
245
star
37

lit-vue

πŸ”₯ Vue SFC goodies directly in JavaScript files.
JavaScript
244
star
38

Miu

🚫 [Deprecated] Miu is a Markdown Editor for Windows (Do not star, this code looks like a sh*t)
JavaScript
241
star
39

tooling.one

A collection of useful tools for developers.
TypeScript
239
star
40

svg-to-vue-component

Transform SVG files into Vue SFC (with hot reloading and SVGO support)
JavaScript
234
star
41

haya

⚑️ esbuild based dev server and production bundler, it's really fast
TypeScript
231
star
42

awesome-esbuild

A curated list of awesome esbuild resources
225
star
43

vue-dts-gen

Generate `d.ts` from `.vue` files.
TypeScript
220
star
44

bget

Download and install binaries from GitHub Releases, interactively.
Go
216
star
45

vue-emotion

Seamlessly use emotion (CSS-in-JS) with Vue.js
JavaScript
214
star
46

vite-plugin-mix

Adding backend API to your Vite app.
TypeScript
210
star
47

mordred

[Experimental] Source data from anywhere, for Next.js, Nuxt.js, Eleventy and many more.
TypeScript
206
star
48

next-fullstack-starter

Next.js + Prisma + TailwindCSS +TRPC
TypeScript
202
star
49

openai-proxy

OpenAI proxy on Cloudflare Worker / Vercel Edge
TypeScript
201
star
50

vue-inter

Simple yet powerful 1kB i18n library for Vue.js
JavaScript
198
star
51

vue-to-react

Turn a Vue component into a React component.
TypeScript
197
star
52

vue-media

A CSS media query component for Vue.js
JavaScript
194
star
53

typed-worker

Type-safe and Promisified API for Web Worker and Iframe
TypeScript
191
star
54

evangelion-card

Generate Evangelion title card like a boss 😎
Vue
188
star
55

vue-html

An alternative to Vue template and Vue JSX
JavaScript
186
star
56

prisma-repl

REPL for Prisma databases.
TypeScript
185
star
57

unplugin-swc

SWC plugin for Vite and Rollup
TypeScript
185
star
58

testen

βœ”οΈ Run tests for multiple versions of Node.js in local env.
JavaScript
175
star
59

vue-cli-gui

GUI for vue-cli UI.
JavaScript
165
star
60

vmark

Convert markdown to Vue component.
JavaScript
164
star
61

bina

An installer for self-contained, single-file binaries, no additional CLI needed.
TypeScript
163
star
62

vue-compile

Compile the blocks in Vue single-file components to use JS/CSS instead of Babel/Sass/Stylus.
TypeScript
158
star
63

is-trademarked-cli

ℒ️ CLI tool to check if a word is trademarked.
JavaScript
158
star
64

play-esbuild

esbuild online playground
TypeScript
157
star
65

vue-prism-component

highlight code using prism.js and vue component
JavaScript
156
star
66

native-toast

Native-like toast notification but for the web.
HTML
150
star
67

loglive

Render changelog as a website on the fly.
JavaScript
149
star
68

logbox

View console logs and errors on any website without opening the devtools
TypeScript
148
star
69

vue-isomorphic-starter

Vue server-side rendering in real life. ~(≧▽≦)/~
JavaScript
147
star
70

vue-ga

Google Analytics for Vue.js
JavaScript
142
star
71

tokio

Web scraping made simple.
JavaScript
142
star
72

taki

Take a snapshot of any website.
TypeScript
140
star
73

esbuild-plugin-vue

Basic .vue support for esbuild.
TypeScript
137
star
74

joycon

Find and load config files with joy.
JavaScript
133
star
75

vue-preload

Preloading data for Vue
JavaScript
133
star
76

bundle-require

bundle and `require` a file, the same way Vite loads `vite.config.ts`
TypeScript
133
star
77

vitekit

Remix and Vite had a baby. [WIP]
TypeScript
132
star
78

md

A markdown parser and compiler. Built for speed.
JavaScript
130
star
79

io-spin

TJ Holowaychuk's go-spin node.js port
JavaScript
125
star
80

vue-windows

Vue components for creating neat windows.
Vue
125
star
81

tsno

`node` with typescript support, importing from URL, etc.
TypeScript
118
star
82

data-tip.css

πŸ’ˆ Wow, such tooltip, with pure css!
HTML
117
star
83

eventstop

A minimal event library for Node.js and browser.
JavaScript
115
star
84

kanpai

🍻 Kanpai is a better way to publish npm packages.
TypeScript
111
star
85

preader

Extract the main content from a web page.
TypeScript
111
star
86

esbuild-service

esbuild as a service. bundle any npm package on the fly as you request.
Go
108
star
87

app-loading

Focus on Medium-like app loading style
JavaScript
104
star
88

vue-slim-tabs

A slim tab component for Vue.js (1.3 kB minified)
Vue
103
star
89

gh-pinned-repos

API service for retrieving pinned repos on GitHub.
TypeScript
103
star
90

follower-count

Get follower count for Instagram, Twitter, TikTok, Youtube accounts
TypeScript
102
star
91

vite-plugin-compile-time

Some compile-time magic for your Vite project
TypeScript
101
star
92

ideas

πŸ’‘ideas / thoughts / polls from egoist
101
star
93

doko

A docker-based development dependency manager.
TypeScript
101
star
94

nswatch

Like gulp.watch but for npm scripts.
TypeScript
100
star
95

npm-size

Get the install size of an npm package.
JavaScript
99
star
96

vue-head

Document <head> manager for Vue 3, SSR ready.
TypeScript
98
star
97

logo-maker

create a simple logo..
CSS
97
star
98

hakka

ALPHA. A reddit-like online community (but less noisy).
TypeScript
96
star
99

always-bet-on-vue

Chunibyo's overwhelming victory
96
star
100

feedbackok-js

Collecting feedback with ease.
TypeScript
94
star