Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaack committed May 15, 2018
1 parent 41563f1 commit 55eaf6f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -79,6 +79,7 @@
"ultradom": "2.0.0"
},
"optionalDependencies": {
"preact": "^8.2.9",
"remotedev": "^0.2.7"
}
}
45 changes: 45 additions & 0 deletions src/enhancers/preact.ts
@@ -0,0 +1,45 @@
import { App } from '../'
import { h, render as _render } from 'preact'

const React = { createElement: h }

export { React, h }

const __HYDUX_RENDER_ROOT__ = '__HYDUX_RENDER_ROOT__'
export default function withUltradom<State, Actions>(container: Element = document.body, options: {
raf?: boolean
} = { raf: true }): (app: App<State, Actions>) => App<State, Actions> {
let rafId
return app => props => app({
...props,
view: (s, a) => {
if (options.raf) {
// Lazy render
return () => props.view(s, a)
}
return props.view(s, a)
},
onRender(view) {
props.onRender && props.onRender(view)
// fix duplicate node in hmr
const render = () => {
if (options.raf) {
view = view()
}
container[__HYDUX_RENDER_ROOT__] = _render(
view,
container,
container[__HYDUX_RENDER_ROOT__],
)
}

if (!options.raf) {
return render()
}
if (rafId) {
window.cancelAnimationFrame(rafId)
}
rafId = window.requestAnimationFrame(render)
}
})
}
2 changes: 2 additions & 0 deletions src/enhancers/router/history.ts
Expand Up @@ -61,6 +61,7 @@ export function matchPath<P>(pathname: string, fmt: string): P | null {
export abstract class BaseHistory {
public location: Location<any, any>
public lastLocation: Location<any, any>
/* @internal */
public _routesMeta: RoutesMeta<any, any>
protected props: HistoryProps
protected _last: string[] = []
Expand Down Expand Up @@ -95,6 +96,7 @@ export abstract class BaseHistory {
parsePath(path: string): Location<any, any> {
return parsePath(path, this._routesTpls)
}
/* @internal */
public _setRoutes(routes: Routes<any, any>, routesMeta: RoutesMeta<any, any>) {
this._routesMeta = routesMeta
this._routes = routes
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Expand Up @@ -28,7 +28,7 @@ export type Dt<T extends string, D = null> = {
* }
* ```
*/
export function dt<T extends string, D>(tag: T, data: D) {
export function dt<T extends string, D = null>(tag: T, data: D = null as any) {
return { tag, data } as Dt<T, D>
}

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -48,7 +48,8 @@

/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"stripInternal": true
},
"include": ["src/**/*"],
"exclude": [
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -3607,6 +3607,10 @@ pre-commit@^1.2.2:
spawn-sync "^1.0.15"
which "1.2.x"

preact@^8.2.9:
version "8.2.9"
resolved "http://registry.npm.taobao.org/preact/download/preact-8.2.9.tgz#813ba9dd45e5d97c5ea0d6c86d375b3be711cc40"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "http://registry.npm.taobao.org/prelude-ls/download/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down

0 comments on commit 55eaf6f

Please sign in to comment.