-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
9 changed files
with
327 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from "react" | ||
|
||
export type Aprops = { | ||
text?: string, | ||
aElement?: React.ReactNode | ||
} | ||
|
||
const AComponent = function ({ text, aElement }: Aprops) { | ||
return <div>{aElement}这是A组件{text} | ||
<input></input> | ||
</div> | ||
} | ||
|
||
export default AComponent |
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,11 @@ | ||
import React from "react" | ||
|
||
const BComponent = function ({ onClick }: Bprops) { | ||
return <div onClick={onClick}>这是B组件</div> | ||
} | ||
|
||
export default BComponent | ||
|
||
export type Bprops = { | ||
onClick?: () => void | ||
} |
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,94 +1,49 @@ | ||
import React, {useEffect } from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import Tanfu from 'tanfu-core'; | ||
import {Component, Controller, EventListener, HostLifeCycle } from 'tanfu-core'; | ||
import { Component, Controller, EventListener, HostLifeCycle } from 'tanfu-core'; | ||
import { RootController } from './index.controller'; | ||
import { BModel, RootModel } from './index.model'; | ||
import { html, TanfuView } from 'tanfu-core'; | ||
import TanfuReactPlugin from '..'; | ||
import AComponent, { Aprops } from './a-component'; | ||
import BComponent, { Bprops } from './b-component'; | ||
|
||
Tanfu.use(new TanfuReactPlugin()) | ||
export default ({ title }: { title: string }) => <Root />; | ||
|
||
|
||
|
||
const AComponent = function ({ text }: Aprops) { | ||
return <div>这是A组件{text}</div> | ||
} | ||
|
||
|
||
|
||
const BComponent = function ({ onClick }: Bprops) { | ||
return <div onClick={onClick}>这是B组件</div> | ||
} | ||
|
||
@Controller() | ||
class BController{ | ||
|
||
@HostLifeCycle('didMount') | ||
didMount(){ | ||
console.log('Bview加载完成了') | ||
} | ||
|
||
@EventListener('div','onClick') | ||
updateDataSource(){ | ||
console.log('更新了dataSource') | ||
} | ||
export type ViewModel = { | ||
a: Aprops, | ||
b: Bprops, | ||
myelementId: Aprops | ||
} | ||
|
||
@Component({ controllers: [BController]}) | ||
export class BView extends TanfuView { | ||
|
||
|
||
update(){ | ||
console.log('触发了自view的方法') | ||
this.dispatchEvent({type: 'div/onClick',payload: undefined }) | ||
} | ||
|
||
template(){ | ||
return html` | ||
<div element-id='div'>自定义的view</div> | ||
` | ||
} | ||
} | ||
|
||
|
||
@Component({ | ||
controllers: [RootController], | ||
providers: [RootModel, BModel], | ||
declarations: [AComponent, BComponent,BView], | ||
declarations: [AComponent, BComponent], | ||
}) | ||
class AView extends Tanfu.View { | ||
|
||
|
||
|
||
template() { | ||
return html` | ||
<a-component element-id="a"> | ||
<a-component t-id="a"> | ||
<div t-slot="aElement">aelemen111t</div> | ||
</a-component> | ||
SFAF | ||
<b-component element-id="b"></b-component> | ||
<b-view element-id="b-view"/> | ||
<b-component t-id="b"></b-component> | ||
<button>button</button> | ||
` | ||
} | ||
} | ||
|
||
const Root = Tanfu.mountView(AView) | ||
|
||
export default ({ title }: { title: string }) => Root; | ||
|
||
|
||
|
||
|
||
export type ViewModel = { | ||
a: Aprops, | ||
b: Bprops, | ||
myelementId: Aprops | ||
} | ||
|
||
type Aprops = { | ||
text?: string | ||
} | ||
|
||
type Bprops = { | ||
onClick?: () => void | ||
} | ||
|
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,16 @@ | ||
import { ComponentArguments } from "."; | ||
import React from 'react' | ||
import htmlTag from "./html-tag"; | ||
|
||
|
||
const reactDeclarations: ComponentArguments['declarations'] = Object.keys(htmlTag).map(key => createDeclaration(htmlTag[key])) | ||
|
||
export default reactDeclarations | ||
|
||
function createDeclaration(tag: keyof JSX.IntrinsicElements) { | ||
const Tag = htmlTag[tag] | ||
return { | ||
name: tag, | ||
value: (props: any) => <Tag {...props} /> | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.