Giter VIP home page Giter VIP logo

subscriptions's Introduction

Ejercicio practico 2

Iniciarlo

Para iniciar la aplicacion deveras descargarla y en el terminal ir a la carpeta y escribir

meteor npm install

una ves instaladas las dependencias deveras escribir en el terminal

meteor

esto ejecutara la app, luego en un browser ir a http://localhost:3000/

Explicacion

Para hacer esta aplicacion aproveche (basicamente lo canibalize) el tutorial de meteor con react, que ya traía un sistema de registro y login funcional, ademas de otras funciones que aproveche.

En App.jsx cree una funcion addUserToList() que se ejecuta al renderisar la pagina, ella revisa si el usuario esta loged y si ya esta en la lista, si no se encuentra en la lista ejecuta Meteor.call('tasks.insert') que se encarga de añadirlo.

Funcion addUserToList()

  addUserToList(){
    const {tasks} = this.props
    const {currentUser} = this.props

    if(tasks[0] && currentUser){
      let userExist = false
      
      tasks.forEach(function(task){
        if(task.username === currentUser.username){
          userExist = true
        }
      })

      if(!userExist){
        Meteor.call('tasks.insert');
      }
    }
  }

Funcion Meteor.call('tasks.insert')

  'tasks.insert'() {
 
    // Make sure the user is logged in before inserting a task
    if (! Meteor.userId()) {
      throw new Meteor.Error('not-authorized');
    }
 
    Tasks.insert({
      createdAt: new Date(),
      owner: Meteor.userId(),
      username: Meteor.user().username,
    });
  },

Luego aprovecho la funcion de privatisacion de tasks que trae ya el tutorial para manejar las subscripcions.

subscriptions's People

Contributors

kv-disco 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.