Skip to content

Instantly share code, notes, and snippets.

View tbuschto's full-sized avatar
🤨

Tim Buschtöns tbuschto

🤨
View GitHub Profile
@tbuschto
tbuschto / tabris-func.js
Last active October 1, 2020 15:37
Self-running snippets for functional tabris components
// eslint-disable-next-line max-len
const {TextView, contentView, NavigationView, Page, drawer, StackLayout, Stack, Row, CollectionView, Button, ImageView, TabFolder, CheckBox, Tab, Composite, TextInput, AlertDialog} = require('tabris');
const examples = MainView().appendTo(contentView);
// This is a standalone, plain JS Tabris app that showcases different use cases
// for functional components. Each self-running function below contains a small
// snippet with explanatory comments. You can see them in action by selecting
// it from the drawer while running the app.
//
@tbuschto
tbuschto / tabris-2-decorators-blog-4-1.tsx
Last active December 21, 2018 15:16
tabris-2-decorators-blog-4-1.tsx
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX, event, ChangeListeners, Listeners } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@event public readonly onTextChanged: ChangeListeners<string>;
@tbuschto
tbuschto / chinese-hello-world.js
Created November 21, 2018 17:41
Chinese Hello World
import {TextView, ui} from 'tabris';
new TextView({
left: 10, top: 10, right: 10, font: '23px',
text: '你好,世界',
alignment: 'left'
}).appendTo(ui.contentView);
import {TextView, CollectionView, Slider, ui, Composite} from 'tabris';
const items = [
'One', 'Two', 'Three', 'Four', 'Five', 'Six',
'Seven', 'Eight', 'Nine', 'Ten', 'Foo', 'Bar', 'Hello World'
]
const MARGIN = 10;
const BORDER = 2;
const TILE_HEIGHT = 128;
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@property public labelText: string;
@tbuschto
tbuschto / tabris-2-decorators-blog-3-1.tsx
Created November 2, 2018 17:21
LabeledInput with data binding
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@property public labelText: string;
@tbuschto
tbuschto / tabris-2-decorators-blog-2-1.tsx
Last active October 18, 2018 09:12
LabeledInput, no databinding
import { ui, Composite } from 'tabris';
import { component, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
private jsxProperties: ComponentJSX<this>;
@tbuschto
tbuschto / Person3.ts
Created May 15, 2018 10:23
decorator factory
import { ui } from 'tabris';
function pattern(regEx: RegExp) {
return (prototype: object, property: string) => {
const sym = Symbol();
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: string) {
if (!regEx.test(value)) {
throw new Error(`Invalid ${property} "${value}"`);
@tbuschto
tbuschto / Person2.ts
Last active May 15, 2018 10:30
generic type check decorator
import 'reflect-metadata';
import { ui } from 'tabris';
function check(prototype: object, property: string) {
const sym = Symbol();
const constr = Reflect.getMetadata('design:type', prototype, property);
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: any) {
if (!(value instanceof constr) && (typeof value !== constr.name.toLocaleLowerCase())) {
@tbuschto
tbuschto / Person.ts
Last active May 15, 2018 10:28
positive decorator
import { ui } from 'tabris';
function positive(prototype: object, property: string) {
const sym = Symbol();
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: number) {
if (value < 0) {
throw new Error('Positive number expected');
}