Learning React Native – Part One

I am now trying to learn react-native from the book Learning React Native.

These are my notes that may help other people following this path.

First problem:

You can’t use npm 5 with create-react-native-app.

This can be resolved by using

npm install -g npm@4.6.1

This will roll npm back to a known good version. Later versions may work (and by the time you read this (it’s April 2018 as I write this) things may have moved on.

 

Note that you will also need to install the Expo app onto your phone.

The phone and your machine need to be on the same network.

This is for the first version of the app that was deployed.

There is also a react-native-cli version, but that requires a more complex android setup.

If you are using Expo it has a built in QR reader.

You may also need to register your own api code to use openweathermap.org.

It’s a bad idea to publish a public key for a free service.

So far this book seems less professionally written than the pragprog
 books that I have been working through recently. 
It does not seem to flow well and has a few rough edges. 
Typically code is added piecemeal but requires style details that 
are not supplied until the full sample.

The weather app is slightly broken. Image can no longer have children. There was no stated version of create-react-native-app so I have installed the latest.

That’s it for now – just finished Chapter 3

Note this is the end of this series of articles. The book was found to have so many broken examples that it was not worth continuing.

Linux Development on Android

It is now possible to start Linux Development on an android device:

https://medium.freecodecamp.org/building-a-node-js-application-on-android-part-1-termux-vim-and-node-js-dfa90c28958f

The above article shows how to install enough onto your phone to allow basic development.

Here is some of the history from my first session

1 apt update && apt upgrade
2 apt install coreutils
8 which awk
9 which sed
10 which grep
11 which curl

# not found so installed via
12 pkg install curl
13 curl
19 apt install vim
21 apt install nodejs
22 which node
24 node -v
25 history

Given that I now have node, vim, curl, grep, awk and sed this looks to be a useful base platform.

Phoenix for Rails Developers – Part 2

I now have the code working upto the cart on the page.

https://github.com/chriseyre2000/storex

Elixir and Phoenix are still great for showing exactly where the error is.

This can be handy as Elixir is very picky on whitespace usage.

Frequent use of:

mix clean

mix phx.routes

Will show any compiler warnings. It’s best to keep on top of these as they do give you clues as to obvious typos. This is especially true of unused variables.

It’s great that a whole chapter was written test first – especially when this demonstrates the DDD concept of Contexts. This is my main bugbear on some of the other Elixir books – tests have been removed to save space.

Also when you add a Plug you need to restart the server – these are not automatically added.

Phoenix for Rails Developers – Part 1

I was lucky enough to win a copy of Phoenix for Rails Developers.

(Thanks to @plataformatec)

This gives me one more thing to study!

Oddly I am not a Rails developer (but have worked on a number of frameworks that were inspired by Rails).

So far I am working through the main examples and will post them here:

https://github.com/chriseyre2000/storex

I am developing this using Visual Studio Code.

Typically I also have two terminal tabs open.

The first is to run the application in:

mix phx.server

or

iex -S phx.server

The second is used for generator or to update git.

I am working with Elixir 1.6.4

So far the book is a gentle introduction to Phoenix. The language is introduced as needed.

It has stayed away from more complex Elixir topics (OTP).

When I have made typos the Elixir compiler will always tell you exactly where you have made the mistake, although it is not always obvious what the mistake was. The live reloading of the web application does allow for very rapid feedback. You do need to remember to restart the app on non-website changes.

The only catch that I have had so far is setting up Postgres locally. All other details have been clearly explained.

Introduction to React

This is a minimal introduction to React. These are intended to be rough notes for my future self. Any other use is entirely fortuitous.

I have taken the Pluralsight course: https://www.pluralsight.com/courses/react-js-getting-started

This is based upon using the online repl found at:  https://jscomplete.com/repl

// This is a simple function based react component.
// Note that the name of the component has to start with a capital.
// You need to treat the props as immutable.

const MyComponent = (props) => {
  return ( 
{props.greeting} {props.name}
); }; // This is a simple class based React component // State is mutable, but you need to use the setState function // so that the UI will be re-rendered. // The state defined here is a proposed js extension that works through Babel. class App extends React.Component { state = {name: "Fred"}; render() { return (
); }; }; // This is the bootstrap that injects React into a page // Here mountNode is an id of a div ReactDOM.render(<App />, mountNode);

 

So from the above sample a quick comparison of React to AngularJs.

React is a view model that can be injected into a page. It follows functional programming idoms (props are immutable, state is updated by returning deltas that are merged into it). The html is embedded into the script so it does not require a distinct template language. It creates a virtual DOM that is dynamically updated when the data changes.

AngularJs is a full framework with routing, templating. It is typically added via custom tags. The developer needs to cede control of a region of a page to angular. Angular typically has distinct templates that are rendered.

They can be made to play well together – React can act as the View to an Angular application.

Operating a Kubernetes Application via 12 Factor Application

For the last few years I have been working on a suite of Heroku applications (previously Azure had similar functionality).

One of the beauty of these is the separation of config and build. This allows the only difference between environments (for secrets such as db connection strings or feature toggle environment variables) to be a versioned secure set of configuration. Importantly these configs can be changed without rebuilding the code.

Here is an article that discusses the capability of running kubernetes as a 12 factor application.

https://www.mirantis.com/blog/how-do-you-build-12-factor-apps-using-kubernetes/

Looking at Kotlin

I like to keep up with languages.

Currently I am studying too many at once (Elixir, Scala, Haskell) so why not add another one.

This is meant to be a best of breed combination of Scala, Groovy and C#

First thought: It’s the first new language that requires explicit returns. Most recent languages that I have used simply treat the last thing in a function as the result.

I have found the  Kotlin Koans project:

git clone https://github.com/Kotlin/kotlin-koans