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 / console_suggest.js
Last active August 6, 2018 13:35
js console autosuggest
function getSuggestions(input) {
var result = {};
var target = getTarget(input);
if (!target) {
return [];
}
var keys = getAllKeys(target);
var part = getLastPart(input);
for (var i = 0; i < keys.length; i++) {
if (keys[i].toLowerCase().startsWith(part.toLowerCase())) {
@tbuschto
tbuschto / Mock.spec
Last active May 22, 2018 21:47
Examples for using mocks in Jasmine Tests
describe( "Mock examples:", function() {
var version = jasmine.version_ ? jasmine.version_.major : parseInt( jasmine.version, 10 );
var spyName = function( spy ) {
if( version === 1 ) {
return spy.identity;
} else {
return spy.and.identity()
}
@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())) {