Skip to content

Instantly share code, notes, and snippets.

View SoEasy's full-sized avatar
🐒
DDD - davai davai deploy

Vladimir Sannikov SoEasy

🐒
DDD - davai davai deploy
  • Ekaterinburg, Russia
View GitHub Profile
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
@SoEasy
SoEasy / split-array-to-chunks.ts
Created November 13, 2019 06:32
Based on generators function for correct split array to chunks
export function* splitArrayToChunks<T>(array: Array<T>, chunkSize: number = Infinity): IterableIterator<Array<T>> {
let resultTasks: Array<T> = [];
for (let i = 0; i < array.length; i += 1) {
const item = array[i];
resultTasks.push(item);
// На последнем элементе если не сделать return -
// генератор завершится только на следующем шаге с пустым массивом
if (i === array.length - 1) {
return resultTasks;
import React, { useEffect, useState } from 'react';
import { Observable } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
export type RxBindProps<T> = {
stream: Observable<T>;
children(dataFromStream: T | void): JSX.Element | Array<JSX.Element> | null;
};
export function RxBind<T>(props: RxBindProps<T>): JSX.Element {
import { useEffect, useState } from 'react';
import { Observable } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
/**
* Компонент-аналог *ngIf - принимает на вход поток Observable<boolean>. Если в поток приходит true - рисует содержимое
*/
export function RxIf(props: { conditionStream: Observable<boolean>, children: JSX.Element }): JSX.Element {
// @ts-ignore
const [state, setState] = useState({ active: false });
@SoEasy
SoEasy / proxy.ts
Last active March 5, 2018 07:00
Наброски прокси-класса
class MetaValidationProxy {
validity$: BehaviorSubject;
attachSource(): void {
// Тут все начальные данные перекинутся в прокси и создастся привязка для проброса данных
}
}
// Класс, в котором без декораторов задаются параметры для валидаций
@Proxy
@SoEasy
SoEasy / tscontract.ts
Created December 12, 2017 13:10
TypeScript contract-based decorators
type MethodDecorator = (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) =>
TypedPropertyDescriptor | void;
type AssertFn = (...args: Array<any>) => void;
class TSContract {
private static isCustomContractInterruptionCb: boolean = false;
private static contractInterruptionCb(message: string): void {
console.warn(message);
@SoEasy
SoEasy / tsdecorators.ts
Last active March 19, 2018 16:01
TypeScript decorators types
type PropertyDecorator = (target: any, propertyKey: string | symbol) => void;
type MethodDecorator = (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) =>
TypedPropertyDescriptor | void;
type ClassDecorator = (target: any) => any;
function ClassDecoratorImpl(...decoratorArgs: Array<any>): ClassDecorator {
console.log('injectable works fine');
return function(target) {
@SoEasy
SoEasy / decorate.ts
Created September 26, 2017 14:52
Decorate property, save metadata, receive metadata after constructor, redefine properties
const protoStore = new WeakMap();
function protoKeys(target) {
let retKeys = [];
while(target.__proto__) {
const pKeys = protoStore.get(target.__proto__);
if (pKeys) {
retKeys = [...retKeys, ...protoStore.get(target.__proto__)];
}
target = target.__proto__;