-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
425ab68
commit 489f463
Showing
10 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export declare const createContext: (defaultValue: any) => any; | ||
export declare const useContext: (Context: any) => any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
var Prop_1 = require("../Prop"); | ||
exports.createContext = function (defaultValue) { | ||
var symbol = Symbol(); | ||
var Context = react_1.createContext(symbol); | ||
var region = new Prop_1.default('data'); | ||
region.set(defaultValue); | ||
Context.write = region.set; | ||
Context.read = region.getValue; | ||
Context.symbol = symbol; | ||
Context.region = region; | ||
return Context; | ||
}; | ||
exports.useContext = function (Context) { | ||
var region = Context.region, symbol = Context.symbol; | ||
var providedValue = react_1.useContext(Context); | ||
var value = region.useValue(); | ||
if (providedValue === symbol) { | ||
return value; | ||
} | ||
return providedValue; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Region from './Region'; | ||
import Prop from './Prop'; | ||
export { createContext, useContext } from './Context'; | ||
export { Region, Prop }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createContext as createReactContext, useContext as useReactContext } from 'react'; | ||
import Prop from '../Prop'; | ||
|
||
export const createContext = (defaultValue: any) => { | ||
const symbol = Symbol(); | ||
const Context = createReactContext(symbol) as any; | ||
const region = new Prop('data'); | ||
region.set(defaultValue); | ||
Context.write = region.set; | ||
Context.read = region.getValue; | ||
Context.symbol = symbol; | ||
Context.region = region; | ||
return Context; | ||
}; | ||
|
||
export const useContext = (Context: any) => { | ||
const { region, symbol } = Context; | ||
const providedValue = useReactContext(Context); | ||
const value = region.useValue(); | ||
if (providedValue === symbol) { | ||
return value; | ||
} | ||
return providedValue; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Region from './Region'; | ||
import Prop from './Prop'; | ||
|
||
export { createContext, useContext } from './Context'; | ||
export { Region, Prop }; |