-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rearchitesting of preact connector. fix context problems
- Loading branch information
Showing
10 changed files
with
127 additions
and
82 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
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,8 +1,4 @@ | ||
|
||
import './vdom' | ||
// import '../../../packages-contrib/react/src/vdom' | ||
|
||
export { flushToDom } from './vdom' // for tests. does SIDE EFFECTS | ||
export { Calendar } from './Calendar' | ||
export { flushToDom } from './utils' // tests need this | ||
|
||
export * from '@fullcalendar/common' |
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,66 @@ | ||
import { options, render, h, Component, createContext as origCreateContext } from 'preact' | ||
|
||
|
||
// TODO: lock version | ||
// TODO: link gh issues | ||
|
||
|
||
export function flushToDom() { | ||
let oldDebounceRendering = options.debounceRendering // orig | ||
let callbackQ = [] | ||
|
||
function execCallbackSync(callback) { | ||
callbackQ.push(callback) | ||
} | ||
|
||
options.debounceRendering = execCallbackSync | ||
render(h(FakeComponent, {}), document.createElement('div')) | ||
|
||
while (callbackQ.length) { | ||
callbackQ.shift()() | ||
} | ||
|
||
options.debounceRendering = oldDebounceRendering | ||
} | ||
|
||
class FakeComponent extends Component { | ||
render() { return h('div', {}) } | ||
componentDidMount() { this.setState({}) } | ||
} | ||
|
||
|
||
export function createContext<T>(defaultValue: T) { | ||
let ContextType = origCreateContext<T>(defaultValue) | ||
let origProvider = ContextType.Provider | ||
|
||
ContextType.Provider = function() { | ||
let isNew = !this.getChildContext | ||
let children = origProvider.apply(this, arguments as any) | ||
|
||
if (isNew) { | ||
let subs = [] | ||
|
||
this.shouldComponentUpdate = (_props) => { | ||
if (this.props.value !== _props.value) { | ||
subs.some(c => { | ||
c.context = _props.value | ||
c.forceUpdate() | ||
}) | ||
} | ||
} | ||
|
||
this.sub = (c) => { | ||
subs.push(c) | ||
let old = c.componentWillUnmount | ||
c.componentWillUnmount = () => { | ||
subs.splice(subs.indexOf(c), 1) | ||
old && old.call(c) | ||
} | ||
} | ||
} | ||
|
||
return children | ||
} | ||
|
||
return ContextType | ||
} |
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
import * as preact from 'preact' | ||
import * as hacks from './preact-hacks' | ||
export { flushToDom } from './preact-hacks' | ||
|
||
declare global { | ||
namespace FullCalendarVDom { | ||
export import Ref = preact.Ref | ||
export import RefObject = preact.RefObject | ||
export import ComponentType = preact.ComponentType | ||
export type VNode = preact.VNode // will NOT forward the props type | ||
export import Context = preact.Context | ||
export import Component = preact.Component | ||
export import ComponentChild = preact.ComponentChild | ||
export import ComponentChildren = preact.ComponentChildren | ||
export import h = preact.h | ||
export import render = preact.render | ||
export import createRef = preact.createRef | ||
export import Fragment = preact.Fragment | ||
export import createContext = hacks.createContext | ||
export type VUIEvent = UIEvent | ||
} | ||
} | ||
|
||
window.FullCalendarVDom = { | ||
Component: preact.Component, | ||
h: preact.h, | ||
render: preact.render, | ||
createRef: preact.createRef, | ||
Fragment: preact.Fragment, | ||
createContext: hacks.createContext | ||
} |
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,5 @@ | ||
|
||
import '../../../packages-contrib/react/src/vdom' | ||
|
||
export function flushToDom() { | ||
} |
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,29 +1,3 @@ | ||
import * as preact from 'preact' | ||
|
||
declare global { | ||
namespace FullCalendarVDom { | ||
export import Ref = preact.Ref | ||
export import RefObject = preact.RefObject | ||
export import ComponentType = preact.ComponentType | ||
export type VNode = preact.VNode // will NOT forward the props type | ||
export import Context = preact.Context | ||
export import Component = preact.Component | ||
export import ComponentChild = preact.ComponentChild | ||
export import ComponentChildren = preact.ComponentChildren | ||
export import h = preact.h | ||
export import render = preact.render | ||
export import createRef = preact.createRef | ||
export import Fragment = preact.Fragment | ||
export import createContext = preact.createContext | ||
export type VUIEvent = UIEvent | ||
} | ||
} | ||
|
||
window.FullCalendarVDom = { | ||
Component: preact.Component, | ||
h: preact.h, | ||
render: preact.render, | ||
createRef: preact.createRef, | ||
Fragment: preact.Fragment, | ||
createContext: preact.createContext | ||
} | ||
export * from './vdom-preact' | ||
// export * from './vdom-react' |
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