Skip to content

Add tutorial 1 of riotjs#12

Merged
eloyesp merged 13 commits intomasterfrom
riot-basic-component
Sep 28, 2017
Merged

Add tutorial 1 of riotjs#12
eloyesp merged 13 commits intomasterfrom
riot-basic-component

Conversation

@lucasroman
Copy link
Contributor

No description provided.

@eloyesp eloyesp self-requested a review July 18, 2017 16:49
@olvap olvap force-pushed the riot-basic-component branch from fc95687 to 6c78733 Compare July 18, 2017 23:42
@olvap
Copy link
Member

olvap commented Jul 18, 2017

@lucasroman te agregué unos detalles y arreglé el largo de algunas lineas. decime que te parece. Por mi ya lo podemos mergear y ver de armar el segundo tutorial.

Copy link
Member

@eloyesp eloyesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El tutorial tiene algunos problemas que ahí te marqué... además hice un plunker donde se puede probar, para asegurar que ande: http://plnkr.co/edit/8PPUPoovZy27RYj00uwU?p=preview


De esta forma, usamos 3 veces la etiqueta. Las dos primeras, se usan definiendo
un nombre y la tercera usa el valor por defecto.
Notar que las etiquetas del componente ```<hello-world/>``` que definimos se
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto es cierto sólo en los archivos .tag, no en html.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No entiendo bien a qué te referís. Querés decir que los saludos personalizados y por defecto sólo funcionan porque es una etiqueta personalizada, en cambio en las etiquetas nativas de HTML no pueden hacer eso. ¿Eso querés decir?.

<h1>hola {name}!</h1>

<script>
name = opts.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto sería this.name = opts.name || "mundo" de esta forma es más simple el montaje del elemento (y es más fácil de utilizar).

Copy link
Member

@olvap olvap Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasroman querés agregar un comentario porque usamos el default en el momento de montar el componente.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bueno acá hay dos cosas para aclarar:

  1. El "this" lo estuvimos discutiendo con @olvap si iba o no. Yo lo borré porque en la guía de riot decía:

Smart ES6 like method syntax is supported: methodName() { } becomes this.methodName = function() {}.bind(this) where this always points to the current tag instance.

Pero puede que lo haya entendido mal y se refería a cuando estás usando del tag en el HTML, no en el archivo .tag. Bueno, si está mal me avisan y lo vuelvo a poner.

  1. Es cierto @eloyesp. Lo hicimos así porque @olvap me enseñó que se pueden pasar atributos al componente en el momento de montarlo. La idea sería mostrar ese concepto.

h1 { color: red; }
</style>

<h1>hola {name}!</h1>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sería mejor usar {opts.name} directamente?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La idea era mostrar que la lógica va en otro lado. a lo mejor podamos hacer algo más complejo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eloyesp la respuesta a tu pregunta es "sí", pero fijate que arriba de ese código hay una lista de elementos que puede tener un tag:

  • CSS
  • HTML
  • Javascript

La idea de ese código es mostrar una correspondencia con esa lista para que se vean claramente esas tres secciones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En ese caso, lo mejor sería agregar algo de javascript real, una posibilidad sería agregar los signos de admiración pasados 5 segundos o algo así:

setTimeout(function () { "agregar el signo de admiración o hacer algo loco" }, 1000)

Copy link
Contributor Author

@lucasroman lucasroman Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listo, ahí subí cambios.

<script>
// El saludo por defecto será "hola mundo!"
riot.mount('hello-world', {name: 'mundo'})
</script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este script va al final del documento o esperar al evento onready. En este caso está andando solo porque tarda en compilar el tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Will be in next commit.

title: "Riot Tutorial 1 - Componente Básico"
date: 2017-07-14 10:00:00 -0300
tags: tutorial
categories: en
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El texto está en español, así que la category sería "es".

<hello-world>
<style>
h1 { color: red; }
</style>
Copy link
Member

@olvap olvap Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... ni

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferiría no incorporar demasiados conceptos nuevos al principio para no complicar a la persona que lo lea, recuerden que sería una de las primeras cosas hechas en riot. Pero si lo consideran útil lo agrego.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Al parecer está bien así....

@julioalucero julioalucero force-pushed the master branch 2 times, most recently from b1f8b52 to d26ebf8 Compare July 21, 2017 17:59
<hello-world></hello-world>

<!-- El script va al final del documento -->
<script type=riot/tag src="hello-world.tag"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en los pasos de arriba, estás poniendo que los scripts los vas agregando en el head, pero cuando los mostrás terminado, están en e body.

```html
<head>
<script type=riot/tag src="hello-world.tag"></script>
</head>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En el texto dice: al final del body pero en el ejemplo está en el head...

@eloyesp eloyesp merged commit ef51487 into master Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants