8/2/16

React - Building Search App (Part 2)

Nested Component

So after we learned that react is components and created our first component - lets see how components may host other components inside themselves:
Lets create SearchBar component which be child component of SearchPage and which will include search text input:



    var SearchBar = React.createClass({
      render: function() {
        return (
          <div><input placeholder="type search term"/></div>
        );
      }
    });  
     var SearchPage = React.createClass({
      render: function() {
        return (
          <div>
              <SearchBar/>
          </div>
        );
      }
    });
    
    ReactDOM.render(
        <SearchPage />,
        document.getElementById('example')
      );
And lets add another child component which will hold the list of search results:


     // Results List
    var ResultsList = React.createClass({
      render: function() {
        return (
          <div className="results">here will come search results.. </div>
        );
      }
     });

     ...
     ...
  
     var SearchPage = React.createClass({
      render: function() {
        return (
          <div>
             <SearchBar/>
             <ResultsList/>
          </div>
        );
      }
    });

Note that in react if you want specify some css class you need to use className

Communication

Ok, you asking yourself, but how those components will communicate one with other?
How searchBar will tell the resultsList to display results?
- Here are two words you must remember when you talking about component communication in react:
props and state , we will talk about them in the next part

7/29/16

React - Building Search App (Part 1)

Get Started

So, if you asking yourself how is it feels to program react - you may easily create your first react app withing seconds:

1. go to plunker
2. click on the down arrow in the green button on the top with caption "new"
3. select "react" or "react with addons" and yes, you have created your first react app!
Yes, it currently only says "Hellow World", but from this second no man can say you never programmed react...

Components are basic part of react

When building React app you must start from building components. So lets create our first component - searchPage


     var SearchPage = React.createClass({
      render: function() {
        return (
          <div>here will come search results...</div>
        );
      }
    });
    
    ReactDOM.render(
        <SearchPage />,
        document.getElementById('example')
      );
running code
Thats it - was not too complicate, right? If you want to get more of this stuff - follow the next part

7/21/16

Building A Short-Description Pipe Angular 2

Pipe is same thing that filter in angluar1. Lets take a look on code that checks if field has too much characters and if it has - replaces the extra characters with ... :


import { Pipe } from '@angular/core';

@Pipe({
  name: 'short_description'
})
export class ShortDescriptionPipe {
  transform(value) {
    let transformedValue;
    if (value && value.length > 100) {
      transformedValue = `${value.substring(0, 100)}...`;
    } else {
      transformedValue = value;
    }

    return transformedValue;
  }


Now if we have some field contain more than 100 characters it will display only first 100 characters

    <div>
      <h2>Hello {{name | short_description }}</h2>      
    </div>

Extending The Pipe To Get "Maximum Chars" Param

In previous code the characters length is statically restricted to 100 chars. But what if we wish to dynamicaaly pass the maximum chars number?


    <div>
      <h2>Hello {{name | short_description : 4}}</h2>      
    </div>
As in angular1 the pipe params prefixed with ::

import { Pipe } from '@angular/core';

@Pipe({
  name: 'short_description'
})
export class ShortDescriptionPipe {
  transform(value, args?) {//args contains param
    if(!args ){
      args= 100;
    }
    let transformedValue;
    if (value && value.length > args) {
      transformedValue = `${value.substring(0, args)}...`;
    } else {
      transformedValue = value;
    }

    return transformedValue;
  }


Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...