[go: up one dir, main page]

Skip to content

surol/surol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 

Repository files navigation

surol's GitHub stats
wakatime

Take a look at my projects

Asynchronous TypeScript-friendly HTTP server
import { httpListener, Rendering } from '@hatsy/hatsy';
import { dispatchByPattern, Routing } from '@hatsy/router';
import { createServer } from 'http';

const server = createServer(httpListener(
  Routing
    .and(Rendering)
    .for(
      dispatchByPattern({
        on: '**',
        to({ renderJson }) {
          renderJson({ hello: 'world' });
        },
      }),
    ),
));

server.listen(3000);
Run that, then this
package.json scripts and deps runner
# First, run `clean` task.
# After that run `build`, `lint`, and `test` tasks simultaneously.
# Then publish the package.
npx run-z clean build,lint,test --then npm publish
(In development) Web components building blocks

An UI framework based on web components.

Features IoC container, loadable features, routing, CSS-in-TS, form validation and processing, etc.

Defines custom elements by decorating a component classes:

import { Attribute, Component, ComponentContext, Render } from '@wesib/wesib';

@Component('greet-text') // Custom element name
export class MyComponent {
  
  @Attribute() // Custom attribute
  name: string;

  constructor(private readonly _context: ComponentContext /* IoC context */) {
  }

  @Render() // Render when component state changes
  render() {
    this._context.contentRoot.innerText = `Hello, ${this.name}!`;
  }

}

No need to extend HTMLElement or any other class. Instead, Wesib creates a custom element accordingly to its definition built either programmatically or using component decorators.

See RealWorld application implemented with Wesib.

Functional event processor

Handle events in reactive style. Think RxJS specialized on events rather generalized for data streams processing.

import { EventEmitter, OnEvent, translateOn } from '@proc7ts/fun-events';
import { Supply } from '@proc7ts/supply';

// API supports arbitrary event receiver signatures
// An event is its receiver's parameters
function printMessage(sender: string, message: string): void { 
  console.info(`Message from ${sender}: ${message}`);
}

const messageEmitter = new EventEmitter<[user: { name: string, email: string }, message: string, urgent?: boolean]>();
const onUrgentMessage: OnEvent<[string, string]> = messageEmitter.on.do(
  translateOn(
    // Translate urgent messages only
    (send, { name, email }, message, urgent = false) => urgent && send(`${name} <${email}>`, message),
  ),
);

// Call the `OnEvent` function to start receiving events
const supply: Supply = onUrgentMessage(printMessage);

// Emit some events
messageEmitter.send({ name: 'Tester', email: 'tester@example.com' }, 'Hello', true);
// Prints: "Message from Tester <tester@example.com>: Hello"
messageEmitter.send({ name: 'Tester', email: 'tester@example.com' }, 'Not so urgent');
// Prints nothing

// Cutting off message supply
supply.off();

// Messages won't be received any more
messageEmitter.send({ name: 'Tester', email: 'tester@example.com' }, 'Too late', true);
// Prints nothing

Other Tools And Libraries

About

Ruslan Lopatin (developer profile)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published