Giter Club home page Giter Club logo

grapher-vue's Introduction

Grapher + Vue

This package makes using Grapher with Vue in Meteor easier and more declarative.

It automatically subscribes to your queries when the component is loaded, and unsubscribes to them when the component is destroyed.

Query parameters are reactive, using Vue's reactivity. So if you for example use this.limit in your query, it will update the query and subscription when this.limit changes. If you use @mitar's fork of Tracker, it will also respond to reactive Meteor variables.

BREAKING CHANGE: Beginning with 1.0, instead of the result being in result.data, the result is the root object, and the extra properties are prefixed with $.

Setup

meteor add herteby:grapher-vue
import GrapherVue from 'meteor/herteby:grapher-vue'
Vue.use(GrapherVue)

Example

<template>
  <div v-if="users.$readyOnce">
    Users: {{users.$count}} of {{users.$fullCount}}<br>
    Time taken: {{users.$time}}ms
    <div v-for="user in users">
      <h4>{{user.username}}</h4>
      <pre>{{user.profile}}</pre>
    </div>
    <button v-if="users.$count < users.$fullCount" @click="limit += 20">Load more</button>
  </div>
  <div v-else>Loading...</div>
</template>

<script>
  export default {
    data(){
      return {
        limit:20,
      }
    },
    grapher:{
      users(){
        return {
          collection:Meteor.users,
          fullCount:true,
          query:{
            $options:{limit:this.limit},
            username:1,
            profile:1
          }
        }
      }
    }
  }
</script>

Demo repo

API

Property Type Required/Default Description
collection Mongo.Collection Required The root collection for the query
query Object Required Argument for Grapher's createQuery()
subscribe Boolean Defaults to true If set to false, uses a method call instead. The result structure is the same regardless
single Boolean or String Defaults to false If set to true, it will work like fetchOne(), and adds $options:{limit:1} to the query. If a String, it also adds $filters:{_id:theString}
fullCount Boolean Defaults to false If true, getCount() will be called to fetch the full count from the server. Useful if you have set a limit on the query
countOnly Boolean Defaults to false If true, only getCount() will be called, and no data will be fetched. Useful for notification badges and such. Instead of the normal format, the result will simply be false initially, and then when getCount() returns, a Number representing the count.
disabled Boolean Defaults to false Disable the query. Use with a reactive Vue variable if you for example want to wait for the user to input a search string, or select which document to show

Extra result properties

Property Type Description
$ready Boolean Wether the subscription has finished fetching all documents
$readyOnce Boolean Unlike ready, this will remain true if the subscription is later changed (useful for loading indicators)
$count Number Number of results
$fullCount Number or false Only available if you set fullCount or countOnly to true.
This will initially be set to false. Once the getCount() server call returns, this will be updated with the count
$time Number How many milliseconds it took to fetch all the data
$disabled Boolean If it's disabled

If you need to get rid of these for some reason, just use this Lodash function:

_.omitBy(result, key => key[0] == '$') //_.omit in Underscore

grapher-vue's People

Contributors

herteby avatar jorgenvatle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

grapher-vue's Issues

Present files on Install

Hi,
when I do meteor add herteby:grapher-vue, compared with your demo, it does not add the following folders and their content:
packages
L__grapher
L__grapher-vue

Is it normal?

Thanks
Marc

Here is my install list:

curl https://install.meteor.com/ | sh              //one time, not for each project
cd vm
meteor create t3
cd t3

meteor remove blaze-html-templates jquery
meteor add static-html akryum:vue-component

meteor add herteby:grapher-vue   
                                                       RESULT:
                                                           cultofcoders:grapher                added, version 1.3.7
                                                           dburles:mongo-collection-instances  added, version 0.3.5
                                                           herteby:denormalize                 added, version 0.6.5
                                                           herteby:grapher-vue                 added, version 1.2.2
                                                           lai:collection-extensions           added, version 0.2.1_1
                                                           matb33:collection-hooks             added, version 0.8.4
                                                           reywood:publish-composite           added, version 1.5.2

meteor npm i -S babel-runtime vue vue-meteor-tracker vue-router
                                                       RESULT:
                                                           + [email protected]
                                                           + [email protected]
                                                           + [email protected]
                                                           + [email protected].

meteor remove autopublish

TypeError: _.cloneDeep is not a function

Meteor version 1.6.1

Seems like Underscore is used instead of lodash, for some reason.

TypeError: _.cloneDeep is not a function
    at VueComponent._this2.$watch.immediate (grapher-vue.js:27)

Vue-SSR error

Hi, i got an error:

TypeError: query.subscribe is not a function
W20171009-18:24:01.740(7)? (STDERR)     at run (packages/herteby:grapher-vue/grapher-vue.js:88:17)
W20171009-18:24:01.741(7)? (STDERR)     at [object Object]._onTimeout (packages/herteby:grapher-vue/grapher-vue.js:148:10)
W20171009-18:24:01.742(7)? (STDERR)     at Timer.listOnTimeout (timers.js:92:15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.