Skip to content
Permalink
Browse files

restructure ready for components

  • Loading branch information...
halfnelson committed Feb 6, 2019
1 parent 2993877 commit f7985641b75b1b13addd053bc4ecc22b16c43fc5

Some generated files are not rendered by default. Learn more.

@@ -16,7 +16,7 @@
"license": "MIT",
"peerDependencies": {
"tns-core-modules": "^5.1.2",
"svelte": "^3.0.0-alpha27"
"svelte": "^3.0.0.beta.2"
},
"devDependencies": {
"rollup": "^1.1.2",
@@ -1,5 +1,3 @@
import { SvelteComponent } from "../global";

export default class AsComponent {
component: SvelteComponent;
}
@@ -0,0 +1 @@
export { default as AsComponent } from './AsComponent'
@@ -3,9 +3,17 @@ import { getViewMeta, normalizeElementName, ComponentMeta } from './element-regi
import * as viewUtil from './utils'
import * as types from 'tns-core-modules/utils/types'
import { isAndroid, isIOS } from 'tns-core-modules/platform'
import { View, EventData } from 'tns-core-modules/ui/core/view/view';
import { View } from 'tns-core-modules/ui/core/view/view';
import DocumentNode from './DocumentNode';

declare module "tns-core-modules/ui/core/view/view" {
interface View {
__SvelteNativeElement__: ViewNode;
}
}

export type EventListener = (args: any) => void;

export function* elementIterator(el:ViewNode):Iterable<ViewNode> {
yield el;
for (let child of el.childNodes) {
@@ -180,13 +188,13 @@ export default class ViewNode {
}

/* istanbul ignore next */
addEventListener(event:string, handler: (args: EventData) => void) {
addEventListener(event:string, handler: EventListener) {
console.log(`add event listener ${this} ${event}`)
this.nativeView.on(event, handler)
}

/* istanbul ignore next */
removeEventListener(event:string, handler?: (args: EventData) => void) {
removeEventListener(event:string, handler?: EventListener) {
console.log(`remove event listener ${this} ${event}`)
this.nativeView.off(event, handler)
}
@@ -2,7 +2,7 @@ import { View } from 'tns-core-modules/ui/core/view'
import ViewNode from './ViewNode'


type ComponentClassResolver = () => View;
export type ComponentClassResolver = () => View;

interface ElementEntry {
resolver: ComponentClassResolver,
@@ -0,0 +1,7 @@
export { default as DocumentNode } from "./DocumentNode"
export { default as ElementNode } from "./ElementNode"
export { default as CommentNode } from "./CommentNode"
export { default as PropertyNode } from "./PropertyNode"
export { default as ViewNode, EventListener } from "./ViewNode"
export { default as TextNode } from "./TextNode"
export { ComponentMeta, registerElement, ComponentClassResolver } from "./element-registry"

This file was deleted.

@@ -2,10 +2,13 @@ import DocumentNode from './dom/DocumentNode'
import ElementNode from './dom/ElementNode'
import { Frame } from 'tns-core-modules/ui/frame'
import { run, on, launchEvent } from 'tns-core-modules/application'
import ViewNode from './dom/ViewNode';
import { SvelteComponent } from './global';

import ViewNode from "./dom/ViewNode";

declare global {
export class SvelteComponent {
constructor(options: { target?: ViewNode, props?: any });
}
}

export function svelteNative(startPage: typeof SvelteComponent, data: any) {
let document = new DocumentNode();
@@ -22,13 +25,11 @@ export function svelteNative(startPage: typeof SvelteComponent, data: any) {
props: data || {}
});
//dirty way to find page's native view
frame.firstChild
console.log("navigating to", frame.firstChild);
(frame.nativeView as Frame).navigate({ create: () => frame.firstChild.nativeView});
(frame.nativeView as Frame).navigate({ create: () => frame.firstElement().nativeView});
})

run({create: () => frame.nativeView});
}

export { default as AsComponent } from "./components/AsComponent.js"
export { default as AsComponent } from "./components/AsComponent"
export { default as ElementNode } from "./dom/ElementNode"
@@ -0,0 +1,2 @@
export { default as proxyEvents } from "./proxy-events";
export { getEventHandlers } from "./shims";
@@ -0,0 +1,26 @@
interface registeredEvent {
type: string
handler: ((event: any) => void)
}

export default function proxyEvents(node: any, events: {[index: string]: ((event: any) => void)[]} ) {

let registeredEvents:registeredEvent[] = [];

for(let type of Object.keys(events)) {
let thisType = type;
let handler = (ev: any) => {
(events[thisType] || []).forEach(fn => fn(ev));
}
node.addEventListener(type, handler);
registeredEvents.push({type, handler});
}

return {
destroy() {
for(let {type, handler} of registeredEvents) {
node.removeEventListener(type, handler);
}
}
}
}
@@ -0,0 +1,5 @@
import { current_component } from "svelte/internal"

export function getEventHandlers(): {[index: string]: ((event: any) => void)[]} {
return current_component.$$.callbacks;
}
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "*": ["types/*"] },
"declaration": true,
"declarationDir": "./dist",
"module": "es2015",
@@ -0,0 +1,9 @@
export function afterUpdate(fn: any): void;
export function beforeUpdate(fn: any): void;
export function createEventDispatcher(): any;
export function getContext(key: any): any;
export function onDestroy(fn: any): void;
export function onMount(fn: any): void;
export function setContext(key: any, context: any): void;
export function tick(): any;

@@ -0,0 +1,10 @@
declare module "svelte/internal" {
interface ComponentInternals {
callbacks: { [index: string]: ((event: any) => void)[] }
}
interface ExposedSvelteComponent {
$$: ComponentInternals
}

export let current_component: ExposedSvelteComponent
}

0 comments on commit f798564

Please sign in to comment.
You can’t perform that action at this time.