Skip to content

Instantly share code, notes, and snippets.

View panvourtsis's full-sized avatar

Panagiotis Vourtsis panvourtsis

View GitHub Profile
{
"dependencies": {
"ng-redux": "^3.4.0-beta.1",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-redux": "^5.0.5",
"react2angular": "^1.1.3",
"redux": "^3.6.0",
"redux-devtools": "^3.4.0",

Code directory structure

├── app - holds all the components
│   ├── common - is not a module of the app. This holds utils for the react app.
│   │   └── utils
│   ├── ratings
│   │   ├── components 
│   │   │   ├── RatingItem 
│   │   │   │   ├── RatingItem.js 

│ │ │ │ └── RatingItem.less

import React from "react";
import PropTypes from "prop-types";
function RatingsItem(props) {
return (
<div>
{props.rating.text}
</div>
);
}
import { ADD_RATINGS } from "./RatingsActions";
const initialState = { list: [] };
const RatingsReducer = (state = initialState, action) => {
switch (action.type) {
case ADD_RATINGS :
return {
...state,
import callApi from "../common/utils/apiCaller";
export const ADD_RATINGS = "ADD_RATINGS";
export function addRatings(ratings) {
return {
type: ADD_RATINGS,
ratings,
};
}
@panvourtsis
panvourtsis / RatingsPage.js
Created June 9, 2017 18:15
high order component
import { connect } from "react-redux";
import React, { Component } from "react";
import PropTypes from "prop-types";
// Import Components
import RatingList from "./components/RatingList/RatingList";
// Import Actions
import { fetchRatings } from "./RatingsActions";
// import Reducer
import { getRatings } from "./RatingsReducer";
class RatingsPage extends Component {
import {combineReducers} from "redux";
import Ratings from "./ratings/RatingsReducer";
// Combine all reducers into one root reducer
export const RootReducer = combineReducers({
Ratings
});
@panvourtsis
panvourtsis / app-sample.js
Created June 9, 2017 18:17
This is a small example of the app.js. The actuall app is going to have more config. You will see some functions missing
import ngRedux from "ng-redux";
import thunk from "redux-thunk";
import {RootReducer} from "./Reducers";
angular
.module(
"funkmartini",
[
...,
ngRedux,
.....
@panvourtsis
panvourtsis / FlatArray.js
Created October 17, 2018 07:32
A function that flattens an array
// if an array has content join all parts to comma seperated string and splitted to a new array
const flatArray = (array) => array.length ? array.join().split(',') : [];
flatArray([[1,2,[3]],4])
flatArray([1,2,3,4])
flatArray([1,2,[3,[4,5]],6])
@panvourtsis
panvourtsis / JSMeetupModule.java
Last active January 3, 2019 13:04
JSMeetup Native Module
package com.JSMeetup;
import ...
class JSMeetupModule extends ReactContextBaseJavaModule {
private static String mPremium = "";
public JSMeetupModule(ReactApplicationContext reactContext) {
super(reactContext);
...