Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-isomorphic-tools

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-isomorphic-tools - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

33

helpers/loadOnServer.js

@@ -52,9 +52,10 @@ 'use strict';

components = (0, _preload2.getComponents)(components);
console.log('loadOnServer', components);
if (!components.length) {
_context.next = 23;
_context.next = 24;
break;
}
_context.prev = 6;
_context.prev = 7;

@@ -64,5 +65,5 @@ dispatch((0, _preload.start)());

case 9:
case 10:
if ((_context.t1 = _context.t0()).done) {
_context.next = 17;
_context.next = 18;
break;

@@ -74,7 +75,7 @@ }

if (!components.hasOwnProperty(i)) {
_context.next = 15;
_context.next = 16;
break;
}
_context.next = 14;
_context.next = 15;
return components[i].preload({

@@ -93,3 +94,3 @@ getState: getState,

case 14:
case 15:
dispatch((0, _preload.push)({

@@ -101,18 +102,18 @@ displayName: components[i].displayName,

case 15:
_context.next = 9;
case 16:
_context.next = 10;
break;
case 17:
case 18:
dispatch((0, _preload.finish)());
_context.next = 23;
_context.next = 24;
break;
case 20:
_context.prev = 20;
_context.t2 = _context['catch'](6);
case 21:
_context.prev = 21;
_context.t2 = _context['catch'](7);
dispatch((0, _preload.error)(_context.t2));
case 23:
case 24:
case 'end':

@@ -122,3 +123,3 @@ return _context.stop();

}
}, _callee, undefined, [[6, 20]]);
}, _callee, undefined, [[7, 21]]);
}));

@@ -125,0 +126,0 @@

@@ -149,2 +149,3 @@ 'use strict';

var getComponents = function getComponents(components) {
console.log('getCOmponents', components);
return components.filter(function (item) {

@@ -151,0 +152,0 @@ return typeof item == 'function' && item.hasOwnProperty('preload') && typeof item.preload == 'function';

{
"name": "react-isomorphic-tools",
"version": "1.1.2",
"version": "1.1.3",
"description": "Authorization, Fetcher, Preload. Tools for ServerSide rendering",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# react-isomorphic-tools
This library contains many tools when helps to build SSR such as:
> Fetcher, fetchToState
> Authorization (react-cookie)
> Preload Data to component on client
> Load(fetch) data on server side
> helpers...
### Auth
```js
import {Auth} from 'react-isomorphic-tools'
```
methods:
* setToken
* setRefreshToken
* getToken
* getRefreshToken
* isAuthenticated
* logout
* setTokenName || default 'token'
* setRefreshTokenName || default 'Bearer '
* setTokenPrefix
* getTokenPrefix
setToken - establishes working token for Fetcher&&FetchToState
When calling Fetcher() if isAuthenticated() === true then add to headers
key Authorization = getTokenPrefix()+getToken()
If token is outdated (and refresh token is set) server must respond http status code == 401 for that would run process token refresh
Will be send POST request to http://BaseUrl/token/refresh with params:{refreshToken} and Fetcher will wait new token
and refreshToken for update then follow rerequest
## Fetcher
```js
import {fetcher, setBaseUrl} from 'react-isomorphic-tools'
setBaseUrl('http://api.itboost.org/app_dev.php/api')
fetcher('/events', {
method: 'GET', /* default 'GET') */
params:{},
baseUrl: null, /* custom baseUrl */
type: 'form-data' /* (default json) */
})
```
> all parameters will be added to request as query string if method == ('GET'||'DELETE')
other in request body
## FetchToState
```js
import React from 'react'
import {connect} from 'react-redux'
import {fetchToState} from 'react-isomorphic-tools'
@connect(state=>({
eventsShow: state.getIn(['fetchData', 'eventsShow'])
}),{fetchToState})
export default class App extends React.Component{
componentDidMount = () => {
const {fetchData, params} = this.props
fetchToState(`/events/${params.id}`, {
params:{
key: 'value'
},
key: 'eventsShow',
method: 'GET',
baseUrl: 'http://example.com/api'
})
}
}
```
## Decorator Preload
```js
import React from 'react'
import {preload} from 'react-isomorphic-tools'
import {connect} from 'react-redux'
@preload(({fetchToState})=> {
return fetchToState('/events', {
key: 'eventsList'
})
})
@connect(state=>({
eventsList: state.getIn(['fetchData', 'eventsList'])
}))
export default class Page extends React.Component {
static displayName = 'TestPage'
render() {
return (
<div>
</div>
)
}
}
```
In preload(preload, restProps)
preload contains:
* getState
* dispatch
* routes
* params
* location
* router
* fetcher
* fetchToState: (url, params) => dispatch(fetchToState(url, params))

@@ -11,2 +11,3 @@ import {push, start, finish, error} from '../actions/preload'

components = getComponents(components)
console.log('loadOnServer', components)
if (components.length) {

@@ -13,0 +14,0 @@ try {

@@ -58,2 +58,3 @@ import lodash from 'lodash'

const getComponents = (components) => {
console.log('getCOmponents', components)
return components.filter((item)=>typeof item == 'function' && item.hasOwnProperty('preload') && typeof item.preload == 'function')

@@ -60,0 +61,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc