@startup-booster/move-mobx
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -0,1 +1,2 @@ | ||
import React from 'react'; | ||
import { MoveClient } from '@startup-booster/move'; | ||
@@ -27,1 +28,7 @@ | ||
): MoveMobxCollection | ||
export interface IConnectionProviderProps { | ||
url: string, | ||
renderBeforeConnection: boolean, | ||
} | ||
export type ConnectionProvider = React.FC<IConnectionProviderProps> |
const { observable } = require('mobx'); | ||
const { connect: baseConnect } = require('@startup-booster/move'); | ||
const { useEffect, useMemo, useState } = require('react'); | ||
const { useEffect, useMemo, useState, createContext, useContext } = require('react'); | ||
@@ -59,3 +59,8 @@ /** @type {function(string): MoveMobxClient} */ | ||
const useConnection = url => { | ||
const ConnectionContext = createContext({ | ||
connection: /** @type {MoveMobxClient} */(null), | ||
connected: false | ||
}); | ||
const ConnectionProvider = ({url, renderBeforeConnection = false, children}) => { | ||
const connection = useMemo(() => connect(url), []); | ||
@@ -72,8 +77,15 @@ const [connected, setConnected] = useState(false); | ||
return { | ||
connection, | ||
connected, | ||
}; | ||
const contextValue = useMemo(() => ({ connection, connected }), [connection, connected]); | ||
if (!connected && !renderBeforeConnection) { | ||
return null; | ||
} | ||
return <ConnectionContext.Provider value={contextValue}> | ||
{children} | ||
</ConnectionContext.Provider> | ||
}; | ||
const useConnection = () => useContext(ConnectionContext); | ||
const useMoveValue = ( | ||
@@ -131,2 +143,3 @@ connection, | ||
useMoveCollection, | ||
ConnectionProvider | ||
} |
{ | ||
"name": "@startup-booster/move-mobx", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"main": "move-mobx.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@startup-booster/move": "0.1.10" | ||
"@startup-booster/move": "0.1.11" | ||
}, | ||
@@ -9,0 +9,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4606
144
+ Added@socket.io/component-emitter@3.1.2(transitive)
+ Added@startup-booster/move@0.1.11(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedengine.io-client@6.6.2(transitive)
+ Addedengine.io-parser@5.2.3(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addednanoid@2.1.11(transitive)
+ Addedshortid@2.2.16(transitive)
+ Addedsocket.io-client@4.8.1(transitive)
+ Addedsocket.io-parser@4.2.4(transitive)
+ Addedws@8.17.1(transitive)
+ Addedxmlhttprequest-ssl@2.1.2(transitive)
Updated@startup-booster/move@0.1.11