Code Monkey home page Code Monkey logo

meteor-tap's Introduction

meteor-tap

tap tap made with meteor for devoxx 2014 conference live coding.

Here is the instruction to recode the live coding.

  • create app
$ meteor create tap
$ cd tap
$ meteor
  • create collection
JS: Taps = new Meteor.Collection('taps');
  • create tabs div
HTML: <div class="tabs">
  • make the div take all the screen so we catch all the click events
CSS:
  .taps {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    text-align: center;
    -webkit-user-select: none;
  }
  • catch click and double click events on the div
  Template.taps.events({
    'dblclick .taps, click .taps': function () {
    }
  });
  • call remote method
JS: Meteor.call('tap');
  • create method (lag compensation, ...)
JS:
  Meteor.methods({
    tap: function() {
      var id = "0";
      if(Taps.findOne(id))
        Taps.update(id, {$inc: {tap: 1}});
      else
        Taps.insert({_id: id, tap: 1});
    }
  });
  • display in console that taps collection changes when we click
BROWSER CONSOLE: Taps.findOne();
  • display the content of the collection, sort by tap (auto sort)
HTML:
  {{#each taps}}
    {{tap}}<br>
  {{/each}}
JS:
  Template.taps.taps = function () {
    return Taps.find({}, {sort: {tap: -1}});
  };
  • add meta for mobile (no scale, device width)
HTML:
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes" />
  • add simple client js lib to handle clicks correctly and quickly on mobile
$ mkdir -p client/compatibility
$ cp ../fastclick.js client/compatibility
JS: Meteor.startup(function () { FastClick.attach(document.body); });
  • deploy on meteor.com
$ meteor deploy tap
$ meteor add accounts-twitter
$ meteor add accounts-ui
HTML: {{> loginButtons}}<br>
  • use userId to differentiate users
JS: var id = this.userId || "0";
  • display user name and lang
HTML: <a href="http://twitter.com/{{username}}">@{{username}}</a> - {{tap}}<br>
JS:
  Template.taps.username = function () {
    var u = Meteor.users.findOne(this._id);
    if(u && u.services) return u.services.twitter.screenName;
    else return "Anne Onymous";
  };
  Template.taps.userlang = function () {
    var u = Meteor.users.findOne(this._id);
    if(u && u.services) return u.services.twitter.lang;
    else return "??";
  };
  • display user pic
HTML: <img src="{{userpic}}"> <a href="http://twitter.com/{{username}}">@{{username}}</a> - {{tap}}<br>
JS:
  Template.taps.userpic = function () {
    var u = Meteor.users.findOne(this._id);
    if(u && u.services) return u.services.twitter.profile_image_url;
  };
  • display user count
HTML: {{totalusers}} users have been logged<br>
JS:
  Template.taps.totalusers = function () {
    return Meteor.users.find().count();
  }
  • security
$ meteor remove insecure
$ meteor remove autopublish
  • pub/sub taps
JS (server):
  Meteor.publish('taps', function () {
    return Taps.find({});
  });
JS: Meteor.subscribe('taps');
  • pub/sub all users but only mandatory fields
JS (server):
  Meteor.publish('allUsers', function () {
    return Meteor.users.find({}, {fields: {
      'services.twitter.lang': 1,
      'services.twitter.screenName': 1,
      'services.twitter.profile_image_url': 1,
    }});
  });
JS: Meteor.subscribe('allUsers');
  • cool layout (optional)
$ cp ../tapPlus.css .
$ cp ../tap.html .
  • deploy again!
$ meteor deploy tap

meteor-tap's People

Contributors

acemtp avatar pascoual avatar

Stargazers

Adrien Joly avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.