Search This Blog

Saturday 28 October 2017

switch between DEV, QA and PROD easily in angular 4/ionic 3

While building any apps its important for a developer to switch between the environments.
below is a simple way i felt for switching environment in angular 2/4 or ionic 2/3.

its easy with a provider and associative arrays. below is an example:

create a provider called environments and use the below:

_envs = {
dev:{
baseURL:"https://somedev.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
}
    qa:{
    baseURL:"https://someqa.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
    },
    prod:{
    baseURL:"https://someprod.exaple.net/api/mobile",
    config:{
    serviceRefName:"/demo1",
    serviceRefname2:"/demo2",
    serviceRefname3:"/demo3",
    //...
    //...
    }
    }
 };

 _env={};
 _selectedEnv = "qa";

 //add this line in constructor
 this._env = this._envs[this._selectedEnv];

 //add this method to the environment provider
 getURL(configUrl){
    console.log("configUrl Sec : "+configUrl);
    //console.log("this._env="+JSON.stringify(this._env));
    console.log("URL="+this._env["baseURL"]+this._env["config"][configUrl]);
    return this._env["baseURL"]+this._env["config"][configUrl];
  }

In components, where you want to call a service,

  • add environment provider dependency
  • use this:  this.environment.getURL("YourSericeName")
for ex: this.environment.getURL("serviceRefname3")

whenever you need to change, simple change the _selectEnv in you Environment provider.
 For ex:
 _selectedEnv = "prod";

It will take the service names from prod obj of _env. this way with a very simple step, you can switch environment in angular.

Note: It has nothing much specific to angular. this logic can be used in any programming language with respective object constructs.

Monday 9 October 2017

MODS 17


OCT 5
  • A11Y - for accessibility not disability 
    • tota11y.com,  a11y.org, koa11y.tool
  • Scott Davis company - Thirsty Head
  • Future is all micro services, currently its all monolithic
  • Kubernetes - IBM's ., container orchestration
  • Swift for web
    • REPL
    • Chris Latner is a genius
    • Protocol oriented
    • LLVM?
    • CodableProtocol - Swift 4 JSON type
    • TaskStorage - delete, save etc 4 props
  • Kitura
    • Open API 2.0 Spec - swagger
  • React Native
    • DogFooding
    • Hot Reloading
    • Configuring instant updates?
    • Expo - Dev tool
      • expo kit for managing custom needs
      • CRNA
    • Testing:
      • Jest - Snapshot Testing
      • Enzyme
    • StoryBook
      • Interactive Dev & Testing
      • Loki - Visual Regression Testing
      • Monkey Runner tests
    • Build & Deploy:
      • fastlane
  • Tools:
    • Lottie - Animations
    • Crashlytics, Sentry
    • Expo Snack
    • Detox - replacement for appium/selenium
    • appitools - Visual automated testing
    • Open STF - for certain devices testing
    • Electrode native - convert to react
  • Building for Next Billion  Users:
    • about PWA's
    • Performance in google chrome set to slow 3G 
    • In slow 3g expected performance:
      • First meaningful paint - 1.6s
      • Time to interactive - 2.5s
      • Page Ready - 3.6s
  • React with GraphQL & Apollo:
    • Redux - State Management
    • Graph QL is server side, which decouples Server endpoints and client
    • GraphQL
      • Only one end point will be there 
      • Client has to query details it needs and GraphQL will call corresponding service/db and executes a query and returns queried data.
      • Its kind of agreement between client and server so, client need not bother about service side changes. it will always return the details queried by the client and in the same format as the query.
      • Query - Read, Mutation - Write, Subscription - Push
      • cycle: Query -> Resolvers (Functions to calculate how to fetch data) -> Connectors
    • Apollo:
      • Client side for GraphQL mostly. it replaces the need for Relay.
OCT 6
  • Data - J.Paul Getty's quote
  • Deep leaning:
    • Yousha Bengio book on deep learning
    • Super long sequence pattern recognition
    • Alpha GO -by google
    • Over fitting in Neural networks
  • BFF (Backend for frontend) with swift:
    • Micro services
    • Be part of swift evolution - Chris Latner
    • Swift on linux works on Ubuntu 14.0 onwards, linux one server platform and android platform as well
    • Foundation & Dispatch are in progress for apple & Linux platforms
    • Web service frame works based on swift are  - Kitura, Perfect, Vapour
    • Swift is best for web interms of performace and storage when compared with Node, Java
  • Citizen Data Scientist:
    • epilipsy?
    • Lyfas
    • ibm.biz/heartmotion - ibm's project
    • PCA - principle component analysis
    • Data science experience in Bluemix
  • Deep Learning by (methods)
    • blundering - experimentation
    • transfer learning - japan cucumber example
    • Simulation
  • Swift Stack developer is a upcoming profile
  • Robust introduction AI:
    • Recurrent neural networks
    • Tensor layer
  • Appless environment:
    • Conversational UI
      • Intents
      • Entity
      • Action
    • Cloud functions (Google) & Lamda (AWS)
    • Siri - apple, Google Assistant - Google, Amazon - Alexa
    • console.actions.google.com - for cloud functions
    • Amazon echo, echo dot,
    • Earcon instead of icon
    • Siri kit by apple for ConvoUI
    • Chat bubbles - Response
    • Mood Analysis - Urgency etc
    • Seamless UI - b/w devices etc
  • RxJS: @ladyleet
    • IxJS - Matt Podwyski is working on
    • Sync .of, .from  -synchronus functions in Rx
    • .share?
    • SpeechRecognition - mozilla/api/web_search_api
    • .switchmap?
    • .merge?
  • Native Script:
    • from teleric like react
    • snippets plugin for easy coding of native script in atom




















Sunday 26 February 2017

Ionic 2 - Hello World!!

After installing Ionic 2, let start coding with it. Ionic 2 project creation is not much different form ionic 1. it uses the same CLI. so, lets issue the command to create the project

ionic start ItsMyCodeShare --v2
so, this creates a blank ionic 2 project. to see it, run the same serve command after going to the project folder:
ionic serve

this will open your project normally with this URL: http://localhost:8100/ with 3 tabs.

let us understand how ionic 2 project structure and how is it rendering your page on to the WebView.
after creating the blank project your folder structure will look like this:

config.xml, src, www are important for development. forget the rest for now.
config.xml contains all the spec, preferences, plugins for each platform.
src contains the source code that we are going to develop.
www contains the transpiled code. 

src contains below folders based on what all will be used:
app
pages
providers
components
pipes

initially it contains only pages folder as the other were not yet created.
app: is the key folder where the app will be initialised. it contains
app.components.ts - this is the file where app starts (after index.html upto my understanding)
app.html - contains the root nav i.e. a placeholder for all navigation of the app
app.module.ts - all the app components, pages, providers to be declared soon after generating them.
app.scss - contains the style for app.html
main.ts 

app.html has <ion-nav [root]="rootPage"></ion-nav>. this ion-nav is the holder for all of the app. the root is loaded when a component is assigned to variable rootPage

if you observe the app.components.ts, the rootPage will be assigned with the component TabsPage.
When the rootPage was assigned, it looks for TabsPage, it is imported in the .ts file at the top.

import { TabsPage } from '../pages/tabs/tabs';

it was being imported from ../pages/tabs/tabs means, from pages->tabs folder it looks for tabs.ts file.
@Component is decorator which contains meta info like it view, providers etc.,
templateUrl tell what to load for tabsPage. so, tabs.html is loaded.

let us observe, tabs.html:
<ion-tabs>
  <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="information-circle"></ion-tab>
  <ion-tab [root]="tab3Root" tabTitle="Contact" tabIcon="contacts"></ion-tab>
</ion-tabs>

ion-tabs is the directive which is the holder for tabs. it contains 3 ion-tabs which holds respective pages. [root] sets the root page for each of the tab.

so now 3 more pages will be loaded based on their paths mentioned in .ts files.

so i guess you got the crux of it. after app initialization, all the things works based on the .ts typescript files and respective html will be loaded from the templateUrl and styles are taken from respective .scss files.

that's it. to understand flow, i would suggest to keep console.log(); and serve.

Ionic 2 - Installation & installation issues

With ionic 2, the top level stack stays as like ionic 1 (internally lots of changes were) i.e. Cordova for communication with hardware, Angular 2 for javascript events and ionic 2 styles/classes for CSS.

so, installing ionic 2 also like ionic 1. Install nodejs & Install corodva, ionic.

  1. Download latest node.js from https://nodejs.org/en/
  2. run the command:  sudo npm install -g ionic cordova
thats it. you are done with the installation. 

sometimes, users who have ionic 1 are getting problems like, if you create a project it will get created some where else etc. for such, completely remove ionic and re-install.

follow the steps below (in mac):
  1. kill running nodejs via terminal: killall -9 node
  2. completely remove below folders
    1.  /usr/local/lib/node_modules
    2. /usr/local/include/node and /node_modules

thats it, run above install command to re-install ionic 2.