Skip to content

Commit

Permalink
update implementation and add prettier for code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Sep 15, 2019
1 parent 3da394a commit 43ff775
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"extends": ["plugin:prettier/recommended", "plugin:react/recommended"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "es5",
"proseWrap": "always",
"arrowParens": "always"
}
16 changes: 8 additions & 8 deletions RNAdMobBanner.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { arrayOf, func, string } from 'prop-types';
import React, { Component } from 'react';
import {
findNodeHandle,
requireNativeComponent,
UIManager,
findNodeHandle,
ViewPropTypes,
} from 'react-native';
import { string, func, arrayOf } from 'prop-types';

import { createErrorFromErrorData } from './utils';

class AdMobBanner extends Component {

constructor() {
super();
this.handleSizeChange = this.handleSizeChange.bind(this);
Expand All @@ -27,8 +25,8 @@ class AdMobBanner extends Component {
loadBanner() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._bannerView),
UIManager.RNGADBannerView.Commands.loadBanner,
null,
UIManager.getViewManagerConfig('RNGADBannerView').Commands.loadBanner,
null
);
}

Expand All @@ -42,7 +40,9 @@ class AdMobBanner extends Component {

handleAdFailedToLoad(event) {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error));
this.props.onAdFailedToLoad(
createErrorFromErrorData(event.nativeEvent.error)
);
}
}

Expand All @@ -53,7 +53,7 @@ class AdMobBanner extends Component {
style={[this.props.style, this.state.style]}
onSizeChange={this.handleSizeChange}
onAdFailedToLoad={this.handleAdFailedToLoad}
ref={el => (this._bannerView = el)}
ref={(el) => (this._bannerView = el)}
/>
);
}
Expand Down
10 changes: 4 additions & 6 deletions RNAdMobInterstitial.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
NativeModules,
NativeEventEmitter,
} from 'react-native';

import { NativeEventEmitter, NativeModules } from 'react-native';
import { createErrorFromErrorData } from './utils';

const RNAdMobInterstitial = NativeModules.RNAdMobInterstitial;
Expand All @@ -24,7 +20,9 @@ const addEventListener = (event, handler) => {
if (mappedEvent) {
let listener;
if (event === 'adFailedToLoad') {
listener = eventEmitter.addListener(mappedEvent, error => handler(createErrorFromErrorData(error)));
listener = eventEmitter.addListener(mappedEvent, (error) =>
handler(createErrorFromErrorData(error))
);
} else {
listener = eventEmitter.addListener(mappedEvent, handler);
}
Expand Down
9 changes: 4 additions & 5 deletions RNAdMobRewarded.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
NativeModules,
NativeEventEmitter,
} from 'react-native';
import { NativeModules, NativeEventEmitter } from 'react-native';

import { createErrorFromErrorData } from './utils';

Expand All @@ -27,7 +24,9 @@ const addEventListener = (event, handler) => {
if (mappedEvent) {
let listener;
if (event === 'adFailedToLoad') {
listener = eventEmitter.addListener(mappedEvent, error => handler(createErrorFromErrorData(error)));
listener = eventEmitter.addListener(mappedEvent, (error) =>
handler(createErrorFromErrorData(error))
);
} else {
listener = eventEmitter.addListener(mappedEvent, handler);
}
Expand Down
21 changes: 12 additions & 9 deletions RNPublisherBanner.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { arrayOf, func, string } from 'prop-types';
import React, { Component } from 'react';
import {
findNodeHandle,
requireNativeComponent,
UIManager,
findNodeHandle,
ViewPropTypes,
} from 'react-native';
import { string, func, arrayOf } from 'prop-types';

import { createErrorFromErrorData } from './utils';

class PublisherBanner extends Component {

constructor() {
super();
this.handleSizeChange = this.handleSizeChange.bind(this);
Expand All @@ -28,8 +26,8 @@ class PublisherBanner extends Component {
loadBanner() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._bannerView),
UIManager.RNDFPBannerView.Commands.loadBanner,
null,
UIManager.getViewManagerConfig('RNDFPBannerView').Commands.loadBanner,
null
);
}

Expand All @@ -50,7 +48,9 @@ class PublisherBanner extends Component {

handleAdFailedToLoad(event) {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error));
this.props.onAdFailedToLoad(
createErrorFromErrorData(event.nativeEvent.error)
);
}
}

Expand All @@ -62,7 +62,7 @@ class PublisherBanner extends Component {
onSizeChange={this.handleSizeChange}
onAdFailedToLoad={this.handleAdFailedToLoad}
onAppEvent={this.handleAppEvent}
ref={el => (this._bannerView = el)}
ref={(el) => (this._bannerView = el)}
/>
);
}
Expand Down Expand Up @@ -116,6 +116,9 @@ PublisherBanner.propTypes = {
onAppEvent: func,
};

const RNDFPBannerView = requireNativeComponent('RNDFPBannerView', PublisherBanner);
const RNDFPBannerView = requireNativeComponent(
'RNDFPBannerView',
PublisherBanner
);

export default PublisherBanner;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"devDependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.14.3"
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-react": "^7.14.3",
"prettier": "^1.18.2"
}
}
7 changes: 2 additions & 5 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export const createErrorFromErrorData = (errorData) => {
const {
message,
...extraErrorInfo
} = errorData || {};
const { message, ...extraErrorInfo } = errorData || {};
const error = new Error(message);
error.framesToPop = 1;
return Object.assign(error, extraErrorInfo);
}
};

0 comments on commit 43ff775

Please sign in to comment.