Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ribajs/core

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ribajs/core - npm Package Compare versions

Comparing version 0.17.2 to 0.18.0

src/binders/index.ts

2

package.json
{
"name": "@ribajs/core",
"description": "Core module of Riba.js",
"version": "0.17.2",
"version": "0.18.0",
"author": "Pascal Garber <pascal@jumplink.eu>",

@@ -6,0 +6,0 @@ "private": false,

@@ -1,41 +0,4 @@

/**
* The default `.` adapter that comes with riba.js. Allows subscribing to
* properties on plain objects, implemented in ES5 natives using
* `Object.defineProperty`.
*/
import { IObserverSyncCallback } from './observer';
import { IAdapter, AdapterFunction, IRef, IObserverSyncCallback, IRVArray } from './interfaces';
export interface IRef {
callbacks: any[];
pointers: any[];
}
/**
* TODO For what is this?
*/
export interface IRVArray extends Array<any> {
__rv: any;
}
export type AdapterFunction = (...args: any[]) => any;
export interface IAdapter {
counter: number;
weakmap: any;
weakReference: (obj: any) => any; // => __rv ?
cleanupWeakReference: (ref: IRef, id: number) => void;
stubFunction: (obj: any, fn: string) => any; // => response ?
observeMutations: (obj: any, ref: string, keypath: string) => void;
unobserveMutations: (obj: IRVArray, ref: string, keypath: string) => void;
observe: (obj: any, keypath: string, callback: IObserverSyncCallback) => void;
unobserve: (obj: any, keypath: string, callback: IObserverSyncCallback) => void;
get: (obj: any, keypath: string) => any;
set: (obj: any, keypath: string, value: any) => void;
}
export interface IAdapters {
[name: string]: IAdapter;
}
export class Adapter implements IAdapter {

@@ -42,0 +5,0 @@

@@ -1,3 +0,4 @@

import $ from 'jquery';
import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import { JQuery as $ } from '../modules';
import { BinderWrapper } from '../services/binder.service';
import { ITwoWayBinder } from '../interfaces';

@@ -4,0 +5,0 @@ export const animateStar: ITwoWayBinder<boolean> = {

@@ -1,3 +0,3 @@

import { IOneWayBinder } from '../services/binder.service';
import { Utils } from '../utils';
import { IOneWayBinder } from '../interfaces';
import { Utils } from '../services/utils';

@@ -4,0 +4,0 @@ export interface IAssign {

@@ -1,3 +0,4 @@

import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import { getString } from '../utils';
import { ITwoWayBinder } from '../interfaces';
import { BinderWrapper } from '../services/binder.service';
import { Utils } from '../services/utils';

@@ -25,3 +26,3 @@ export const checked: ITwoWayBinder<string> = {

if ((el as HTMLInputElement).type === 'radio') {
(el as HTMLInputElement).checked = getString((el as HTMLInputElement).value) === getString(value);
(el as HTMLInputElement).checked = Utils.getString((el as HTMLInputElement).value) === Utils.getString(value);
} else {

@@ -28,0 +29,0 @@ (el as HTMLInputElement).checked = !!value;

@@ -1,3 +0,4 @@

import $ from 'jquery';
import { IOneWayBinder, BinderWrapper } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';
import { JQuery as $ } from '../modules/jquery.module';
import { BinderWrapper } from '../services/binder.service';

@@ -4,0 +5,0 @@ export const classStar: IOneWayBinder<boolean> = function(el: HTMLElement, value: boolean) {

@@ -1,3 +0,4 @@

import $ from 'jquery';
import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import { ITwoWayBinder } from '../interfaces';
import { JQuery as $ } from '../modules/jquery.module';
import { BinderWrapper } from '../services/binder.service';

@@ -4,0 +5,0 @@ export const addClass: ITwoWayBinder<string> = {

@@ -1,3 +0,4 @@

import $ from 'jquery';
import { IOneWayBinder, BinderWrapper } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';
import { JQuery as $ } from '../modules/jquery.module';
import { BinderWrapper } from '../services/binder.service';

@@ -4,0 +5,0 @@ /**

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,5 +0,5 @@

import { IBindable } from '../binding';
import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import { IBindable, ITwoWayBinder } from '../interfaces';
import { BinderWrapper } from '../services/binder.service';
import { View } from '../view';
import { times } from '../utils';
import { Utils } from '../services/utils';

@@ -105,3 +105,3 @@ export const eachStarBinder: ITwoWayBinder<any[]> = {

if (this.customData.iterated.length > collection.length) {
times(this.customData.iterated.length - collection.length, () => {
Utils.times(this.customData.iterated.length - collection.length, () => {
const view = this.customData.iterated.pop();

@@ -108,0 +108,0 @@ view.unbind();

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,3 @@

import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import { ITwoWayBinder } from '../interfaces';
import { BinderWrapper } from '../services/binder.service';
import { View } from '../view';

@@ -3,0 +4,0 @@

@@ -0,4 +1,4 @@

import { ITwoWayBinder, eventHandlerFunction } from '../interfaces';
// import Debug from 'debug';
import { BinderWrapper, ITwoWayBinder } from '../services/binder.service';
import { eventHandlerFunction } from '../binding';
import { BinderWrapper } from '../services/binder.service';

@@ -5,0 +5,0 @@ /**

@@ -1,3 +0,4 @@

import $ from 'jquery';
import { IOneWayBinder, BinderWrapper } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';
import { JQuery as $ } from '../modules/jquery.module';
import { BinderWrapper } from '../services/binder.service';

@@ -4,0 +5,0 @@ export const removeClass: IOneWayBinder<string> = (el: HTMLElement, value: string) => {

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,3 +0,4 @@

import { ITwoWayBinder, BinderWrapper } from '../services/binder.service';
import JQuery from 'jquery';
import { BinderWrapper } from '../services/binder.service';
import { JQuery } from '../modules/jquery.module';
import { ITwoWayBinder } from '../interfaces';

@@ -4,0 +5,0 @@ // TODO this as custom binder? No web component staff for all fallback finders? eg rv-ca-* ca stands for component attribute

@@ -1,2 +0,2 @@

import { IOneWayBinder } from '../services/binder.service';
import { IOneWayBinder } from '../interfaces';

@@ -3,0 +3,0 @@ /**

@@ -1,5 +0,4 @@

import Debug from 'debug';
import { ITwoWayBinder } from '../services/binder.service';
import { getString, getInputValue } from '../utils';
import $ from 'jquery';
import { Debug, JQuery as $ } from '../modules';
import { ITwoWayBinder } from '../interfaces';
import { Utils } from '../services/utils';

@@ -47,7 +46,7 @@ const debug = Debug('binder:value');

unbind(el) {
unbind(el: HTMLUnknownElement) {
$(el).off(this.customData.event, this.customData.callback);
},
routine(el: HTMLElement, value) {
routine(el: HTMLElement, value: string | string[]) {
const oldValue = this.getValue((el as HTMLInputElement));

@@ -59,8 +58,8 @@ debug('routine value', value);

if (this.customData.isRadio) {
el.setAttribute('value', value);
el.setAttribute('value', value as string);
} else {
if ((el as HTMLSelectElement).type === 'select-multiple' && el instanceof HTMLSelectElement) {
if (value instanceof Array) {
for (let i = 0; i < el.length; i++) {
const option = el[i] as HTMLOptionElement;
for (let i = 0; i < el.options.length; i++) {
const option = el.options[i] as HTMLOptionElement;
option.selected = value.indexOf(option.value) > -1;

@@ -70,8 +69,8 @@ }

} else if (el.getAttribute('contenteditable')) {
if (getString(value) !== oldValue) {
el.innerHTML = value; // TODO write test for contenteditable
if (Utils.getString(value as string) !== oldValue) {
el.innerHTML = value as string; // TODO write test for contenteditable
}
} else {
if (getString(value) !== oldValue) {
(el as HTMLInputElement).value = value != null ? value : '';
if (Utils.getString(value as string) !== oldValue) {
(el as HTMLInputElement).value = value != null ? value as string : '';
}

@@ -82,3 +81,3 @@ }

getValue: getInputValue,
getValue: Utils.getInputValue,
};
import { PRIMITIVE, KEYPATH, parseType } from './parsers';
import { Observer, IObserverSyncCallback } from './observer';
import { Binder, IOneWayBinder, ITwoWayBinder } from './services/binder.service';
import { Observer } from './observer';
import {
Binder,
IOneWayBinder,
ITwoWayBinder,
IOneTwoFormatter,
IFormatterObservers,
eventHandlerFunction,
IObserverSyncCallback,
} from './interfaces';
import { View } from './view';
import { getInputValue, Utils } from './utils';
import { IOneTwoFormatter } from './services/formatter.service';
import Debug from 'debug';
import { Utils } from './services/utils';
import { Debug } from './modules';
export interface IBindable {
binder?: Binder<any>;
/**
* Name of the binder without the prefix
*/
type: string | null;
el: HTMLElement;
/**
* Observes the object keypath
* @param obj
* @param keypath
*/
observe(obj: any, keypath: string, callback: IObserverSyncCallback): Observer;
/**
* Subscribes to the model for changes at the specified keypath. Bi-directional
* routines will also listen for changes on the element to propagate them back
* to the model.
*/
bind(): void;
/**
* Unsubscribes from the model and the element.
*/
unbind(): void;
/**
* Updates the binding's model from what is currently set on the view. Unbinds
* the old model first and then re-binds with the new model.
* @param {any} models
*/
update?(models: any): void;
publish?(): void;
sync?(): void;
}
export interface IFormatterObservers {
[key: string]: {
[key: string]: Observer,
};
}
export type eventHandlerFunction = (event: Event) => void;
/**

@@ -430,3 +387,3 @@ * A single binding between a model attribute and a DOM element.

} else {
return getInputValue(el);
return Utils.getInputValue(el);
}

@@ -433,0 +390,0 @@ }

@@ -1,17 +0,6 @@

import './modules/polyfills.module';
import JQuery from 'jquery';
import { JQuery } from './modules';
import {
Riba,
// formatters
compareFormatters,
mathFormatters,
propertyFormatters,
specialFormatters,
stringFormatters,
// binders
basicBindersWrapper,
coreModule,
} from './index';

@@ -23,13 +12,6 @@

// regist formatters
riba.formatterService.regists(compareFormatters);
riba.formatterService.regists(mathFormatters);
riba.formatterService.regists(propertyFormatters);
riba.formatterService.regists(specialFormatters);
riba.formatterService.regists(stringFormatters);
riba.module.regist(coreModule);
// regist binders
riba.binderService.regists(basicBindersWrapper(JQuery));
(window as any).riba = riba;
export default riba;

@@ -1,11 +0,18 @@

import { IOptionsParam, IViewOptions } from '../riba';
import {
IFormatterObservers,
IBindable,
IModuleBinders,
IModuleFormatters,
IClassicComponent,
IComponents,
IObservers,
IObserverSyncCallback,
IAdapters,
IOptionsParam,
IViewOptions,
} from '../interfaces';
import { PRIMITIVE, KEYPATH, parseType, parseDeclaration } from '../parsers';
import { IFormatterObservers, IBindable } from '../binding';
import { IBinders } from '../services/binder.service';
import { IFormatters } from '../services/formatter.service';
import { View } from '../view';
import { IClassicComponent, IComponents } from '../services/component.service';
import { Observer, IObservers, IObserverSyncCallback } from '../observer';
import { IAdapters } from '../adapter';
import { Utils, camelCase } from '../utils';
import { Observer } from '../observer';
import { Utils } from '../services/utils';

@@ -16,3 +23,3 @@ export interface IBoundElement extends HTMLElement {

export interface IFormattersObservers {
export interface IModuleFormattersObservers {
[propertyName: string]: IFormatterObservers;

@@ -41,3 +48,3 @@ }

public keypaths: IKeypaths = {};
public formattersObservers: IFormattersObservers = {};
public formattersObservers: IModuleFormattersObservers = {};
public observers: IObservers;

@@ -131,5 +138,5 @@ public bindingPrefix: string; // = riba.fullPrefix;

adapters: <IAdapters> Object.create(null),
binders: <IBinders<any>> Object.create(null),
binders: <IModuleBinders<any>> Object.create(null),
components: <IComponents> Object.create(null),
formatters: <IFormatters> Object.create(null),
formatters: <IModuleFormatters> Object.create(null),

@@ -210,3 +217,3 @@ // other

if (attribute.name.indexOf(this.bindingPrefix) !== 0) {
const propertyName = camelCase(attribute.name);
const propertyName = Utils.camelCase(attribute.name);
const declaration = attribute.value;

@@ -213,0 +220,0 @@ const parsedDeclaration = parseDeclaration(declaration);

@@ -1,5 +0,5 @@

import Debug from 'debug';
import { Debug } from '../modules';
import { RibaComponent, IRibaComponentContext } from './riba-component';
import { View } from '../view';
import { EventHandler } from '../riba';
import { EventHandler } from '../interfaces';

@@ -6,0 +6,0 @@ export declare class RibaComponentClass extends RibaComponent {

@@ -7,7 +7,8 @@ /**

import Debug from 'debug';
import { Debug } from '../modules';
import { EventHandler } from '../interfaces';
import { View } from '../view';
import { Riba, EventHandler } from '../riba';
import { Riba } from '../riba';
import { Binding } from '../binding';
import { isJson, camelCase } from '../utils';
import { Utils } from '../services/utils';
import { FakeHTMLElement } from './fake-html-element';

@@ -148,3 +149,3 @@

}
} else if (isJson(attr)) {
} else if (Utils.isJson(attr)) {
value = JSON.parse(attr as any);

@@ -244,3 +245,3 @@ }

newValue = this.parseAttribute(newValue);
attributeName = camelCase(attributeName);
attributeName = Utils.camelCase(attributeName);
this.debug('attributeChangedCallback called', attributeName, oldValue, newValue, namespace);

@@ -247,0 +248,0 @@

@@ -9,3 +9,3 @@ /**

import { IFormatters } from '../../services/formatter.service';
import { IModuleFormatters } from '../../interfaces';

@@ -26,4 +26,4 @@ // compare functions

export const compareFormatters: IFormatters = {
export const compareFormatters: IModuleFormatters = {
and, between, egt, eq, gt, ne, lt, elt, or, not,
};

@@ -1,5 +0,5 @@

export { compareFormatters } from './compare/index';
export { mathFormatters } from './math/index';
export { propertyFormatters } from './property/index';
export { specialFormatters } from './special/index';
export { stringFormatters } from './string/index';
export * from './compare/index';
export * from './math/index';
export * from './property/index';
export * from './special/index';
export * from './string/index';

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { IFormatters } from '../../services/formatter.service';
import { IModuleFormatters } from '../../interfaces';

@@ -8,3 +8,3 @@ // math formatters

import { numberFormatter } from './number.formatter';
import { times } from './times.formatter';
import { timesFormatter } from './times.formatter';
import { dividedBy } from './dividedBy.formatter';

@@ -17,6 +17,6 @@ import { modulo } from './modulo.formatter';

export { random, plus, minus, numberFormatter, times, dividedBy, modulo, gcd, even, uneven, digits };
export { random, plus, minus, numberFormatter, timesFormatter, dividedBy, modulo, gcd, even, uneven, digits };
export const mathFormatters: IFormatters = {
digits, dividedBy, even, gcd, minus, number: numberFormatter, modulo, plus, random, times, uneven,
export const mathFormatters: IModuleFormatters = {
digits, dividedBy, even, gcd, minus, number: numberFormatter, modulo, plus, random, times: timesFormatter, uneven,
};

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -5,4 +5,4 @@ /**

*/
export const times = (a: string | number, b: string | number) => {
export const timesFormatter = (a: string | number, b: string | number) => {
return Number(a) * Number(b);
};

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { IFormatters } from '../../services/formatter.service';
import { IModuleFormatters } from '../../interfaces';

@@ -18,4 +18,4 @@ // property / object / array formatters

export const propertyFormatters: IFormatters = {
export const propertyFormatters: IModuleFormatters = {
parse, first, last, contains, get, set, match, size, empty, isLast, range,
};

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

import { get } from './get.formatter';
import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -4,0 +4,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { IFormatters } from '../../services/formatter.service';
import { IModuleFormatters } from '../../interfaces';

@@ -14,4 +14,4 @@ // special helper formatters

export const specialFormatters: IFormatters = {
export const specialFormatters: IModuleFormatters = {
args, boolean: booleanFormatter, debug, default: defaultBinder, call, currency, json,
};

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';
import { empty } from '../property/empty.formatter';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import { IFormatters } from '../../services/formatter.service';
import { IModuleFormatters } from '../../interfaces';

@@ -23,4 +23,4 @@ // string formatters

export const stringFormatters: IFormatters = {
export const stringFormatters: IModuleFormatters = {
append, downcase, filled, isString, handleize, pluralize, prepend, upcase, replace, replace_first, slice, strip, strip_html, string: stringFormatter,
};

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ export const pluralize = (input: any, singular: string, plural: string) => {

@@ -1,2 +0,2 @@

import { Utils } from '../../utils';
import { Utils } from '../../services/utils';

@@ -3,0 +3,0 @@ /**

@@ -1,19 +0,35 @@

import './modules/polyfills.module';
export * from './modules/jquery.module';
export * from './modules/debug.module';
export * from './services/binder.service';
export * from './services/component.service';
export * from './services/event-dispatcher.service';
export * from './services/formatter.service';
export * from './interfaces';
export * from './modules';
export * from './services';
export * from './adapter';
export * from './binders/basic.binders';
export * from './binders';
export * from './components';
export * from './formatters';
export * from './binding';
export * from './components/index';
export * from './formatters/index';
export * from './parsers';
export * from './riba';
export * from './utils';
export * from './view';
import { JQuery } from './modules';
import { IRibaModule } from './interfaces';
import { basicBindersWrapper } from './binders';
import {
compareFormatters,
mathFormatters,
propertyFormatters,
specialFormatters,
stringFormatters,
} from './formatters';
import * as services from './services';
export const coreModule: IRibaModule = {
formatters: {
...specialFormatters,
...compareFormatters,
...mathFormatters,
...stringFormatters,
...propertyFormatters,
},
binders: basicBindersWrapper(JQuery),
services,
};

@@ -1,2 +0,2 @@

import $ from 'jquery';
import jquery from 'jquery';

@@ -6,8 +6,8 @@ /**

*/
import touchEvents from './jquery-touch-events';
import touchEvents from './_jquery-touch-events';
// tslint:disable-next-line:variable-name
const JQuery: JQueryStatic = touchEvents($);
const JQuery: JQueryStatic = touchEvents(jquery);
export default JQuery;
export { JQuery };
import { IAdapters } from './adapter';
import { isObject } from './utils';
import { IViewOptions } from './riba';
import { IAdapters, Root, IKey, IObserverSyncCallback, Obj, IViewOptions } from './interfaces';
import { Utils } from './services/utils';
export interface IObserverSyncCallback {
sync: () => void;
}
export interface IKey {
path: any;
i: Root;
}
export interface IObservers {
[key: string]: Observer;
}
export type Obj = any;
export type Root = any;
export class Observer {

@@ -89,3 +72,3 @@

this.target = this.realize();
if (isObject(this.target)) {
if (Utils.isObject(this.target)) {
this.set(true, this.key, this.target, this.callback);

@@ -141,3 +124,3 @@ }

token = this.tokens[index];
if (isObject(current)) {
if (Utils.isObject(current)) {
if (typeof this.objectPath[index] !== 'undefined') {

@@ -180,7 +163,7 @@ prev = this.objectPath[index];

if (next !== this.target) {
if (isObject(this.target)) {
if (Utils.isObject(this.target)) {
this.set(false, this.key, this.target, this.callback);
}
if (isObject(next)) {
if (Utils.isObject(next)) {
this.set(true, this.key, next, this.callback);

@@ -205,3 +188,3 @@ }

public value() {
if (isObject(this.target)) {
if (Utils.isObject(this.target)) {
return this.get(this.key, this.target);

@@ -217,3 +200,3 @@ }

public setValue(value: any) {
if (isObject(this.target)) {
if (Utils.isObject(this.target)) {
Observer.adapters[this.key.i].set(this.target, this.key.path, value);

@@ -262,3 +245,3 @@ }

if (isObject(this.target)) {
if (Utils.isObject(this.target)) {
this.set(false, this.key, this.target, this.callback);

@@ -265,0 +248,0 @@ }

@@ -1,2 +0,2 @@

import { isJson } from './utils';
import { Utils } from './services/utils';

@@ -41,3 +41,3 @@ import { IDataElement, View, TBlock } from './view';

value = Number(str);
} else if (isJson(str)) {
} else if (Utils.isJson(str)) {
value = JSON.parse(str);

@@ -44,0 +44,0 @@ } else {

@@ -1,20 +0,21 @@

import { Utils } from './utils';
import {
IModuleFormatters,
IModuleBinders,
ITwoWayBinder,
IAdapters,
Root,
IComponents,
IClassicComponent,
IOptionsParam,
IViewOptions,
} from './interfaces';
import { Utils } from './services/utils';
import { parseTemplate, parseType } from './parsers';
import { IFormatters, FormatterService } from './services/formatter.service';
import { Binding } from './binding';
import { adapter } from './adapter';
import { IBinders, BindersService, ITwoWayBinder } from './services/binder.service';
import { View } from './view';
import { IAdapters } from './adapter';
import { Observer, Root } from './observer';
import { IClassicComponent, IComponents, ComponentService } from './services/component.service';
import { Observer } from './observer';
import { ModulesService } from './services/module.service';
export interface IExtensions {
binders?: IBinders<any>;
formatters?: IFormatters;
components?: IComponents;
adapters?: IAdapters;
}
/**

@@ -74,63 +75,2 @@ * Event handler to liste for publish binder event for two-way-binding in web components

/** Interface for the event handler, augment the event handler of the on-* binder */
export type EventHandler = (this: any, context: Binding, ev: Event, binding: Binding, el: HTMLElement) => void;
export interface IOptions {
/** Attribute / web-component prefix in templates */
prefix?: string;
/** Attribute/ web-component prefix + '-' */
fullPrefix?: string;
/** Preload templates with initial data on bind */
preloadData?: boolean;
/** Root sightglass interface for keypaths */
rootInterface?: string;
/** Template delimiters for text bindings */
templateDelimiters?: Array<string>;
/** Augment the event handler of the on-* binder */
handler?: EventHandler;
starBinders?: any;
removeBinderAttributes?: boolean;
executeFunctions?: boolean;
}
export declare interface IOptionsParam extends IExtensions, IOptions {}
export declare interface IViewOptions extends IOptionsParam {
binders: IBinders<any>;
formatters: IFormatters;
components: IComponents;
adapters: IAdapters;
/** Attribute / web-component prefix in templates */
prefix: string;
/** Attribute/ web-component prefix + '-' */
fullPrefix: string;
/** Preload templates with initial data on bind */
preloadData: boolean;
/** Root sightglass interface for keypaths */
rootInterface: string;
/** Template delimiters for text bindings */
templateDelimiters?: Array<string>;
/** Augment the event handler of the on-* binder */
handler?: EventHandler;
starBinders: any;
removeBinderAttributes: boolean;
executeFunctions: boolean;
}
export class Riba {

@@ -156,10 +96,6 @@

public binderService: BindersService;
public module: ModulesService;
public componentService: ComponentService;
public formatterService: FormatterService;
/** Global binders */
public binders: IBinders<any> = {};
public binders: IModuleBinders<any> = {};

@@ -170,3 +106,3 @@ /** Global components. */

/** Global formatters. */
public formatters: IFormatters = {};
public formatters: IModuleFormatters = {};

@@ -214,5 +150,3 @@ /** Global (sightglass) adapters. */

constructor() {
this.binderService = new BindersService(this.binders);
this.componentService = new ComponentService(this.components);
this.formatterService = new FormatterService(this.formatters);
this.module = new ModulesService(this.binders, this.components, this.formatters);
if (Riba.instance) {

@@ -304,5 +238,5 @@ return Riba.instance;

adapters: <IAdapters> {},
binders: <IBinders<any>> {},
binders: <IModuleBinders<any>> {},
components: <IComponents> {},
formatters: <IFormatters> {},
formatters: <IModuleFormatters> {},

@@ -309,0 +243,0 @@ // other

@@ -1,50 +0,12 @@

import Debug from 'debug';
import { Binding, IBindable } from '../binding';
/**
* One way binder interface
*/
export type IOneWayBinder<ValueType> = (this: Binding, element: HTMLElement, value: ValueType) => void;
import { Debug } from '../modules';
import { Binder, IModuleBinderWrapper, IModuleBinders } from '../interfaces';
import { Utils } from './utils';
/**
* To way binder interface
*/
export interface ITwoWayBinder<ValueType> {
routine: (this: Binding, element: HTMLElement, value: ValueType) => void;
bind?: (this: Binding, element: HTMLElement) => void;
unbind?: (this: Binding, element: HTMLElement) => void;
update?: (this: Binding, model: any) => void;
getValue?: (this: Binding, element: HTMLElement) => void;
block?: boolean;
function?: boolean;
publishes?: boolean;
priority?: number;
}
/**
* A binder can be a one way binder or a two way binder
*/
export type Binder<ValueType> = IOneWayBinder<ValueType> | ITwoWayBinder<ValueType>;
/**
* A list of binders with any key name
*/
export interface IBinders<ValueType> {
[name: string]: Binder<ValueType>;
}
/**
* This wrapper i used to store the binder name in the name property
*/
export interface IBinderWrapperResult {
name: string;
binder: Binder<any>;
}
/**
* This wrapper is used if you need to pass over some dependencies for your binder
*/
export type BinderWrapper = (...deps: any[]) => IBinderWrapperResult;
export type BinderWrapper = (...deps: any[]) => IModuleBinderWrapper;
export class BindersService {
private binders: IBinders<any>;
private binders: IModuleBinders<any>;
private debug = Debug('binders:BindersService');

@@ -56,3 +18,3 @@

*/
constructor(binders: IBinders<any>) {
constructor(binders: IModuleBinders<any>) {
this.binders = binders;

@@ -66,7 +28,7 @@ }

*/
public registWrapper(binderWrapper: IBinderWrapperResult, name?: string): IBinders<any> {
public registWrapper(binderWrapper: IModuleBinderWrapper, name?: string): IModuleBinders<any> {
if (!name) {
name = binderWrapper.name;
}
const binder = (binderWrapper as IBinderWrapperResult).binder;
const binder = (binderWrapper as IModuleBinderWrapper).binder;
this.binders[name] = binder;

@@ -81,6 +43,6 @@ return this.binders;

*/
public regist(binder: Binder<any> | IBinderWrapperResult, name?: string): IBinders<any> {
public regist(binder: Binder<any> | IModuleBinderWrapper, name?: string): IModuleBinders<any> {
if (binder.hasOwnProperty('binder')) {
binder = (binder as IBinderWrapperResult);
binder = (binder as IModuleBinderWrapper);
if (!name) {

@@ -107,10 +69,18 @@ name = (binder as any).name;

*/
public regists(binders: IBinders<any>): IBinders<any> {
for (const name in binders) {
if (binders.hasOwnProperty(name)) {
this.regist(binders[name], name);
public regists(binders: IModuleBinderWrapper[] | IModuleBinders<any>): IModuleBinders<any> {
if (Utils.isArray(binders)) {
for (let index = 0; index < binders.length; index++) {
const binder = (binders as IModuleBinderWrapper[])[index];
this.regist(binder.binder, binder.name);
}
}
if (Utils.isObject(binders)) {
for (const name in binders) {
if (binders.hasOwnProperty(name)) {
this.regist((binders as IModuleBinders<any>)[name], name);
}
}
}
return this.binders;
}
}

@@ -1,51 +0,5 @@

import Debug from 'debug';
import { IBinders } from './binder.service';
import { IFormatters } from './formatter.service';
import { IAdapters } from '../adapter';
import { IBindable } from '../binding';
import { Debug } from '../modules';
import { IClassicComponent, IComponentWrapperResult, IComponents } from '../interfaces';
import { RibaComponent } from '../components/riba-component';
export type Scope = any;
export interface IClassicComponent<ValueType> {
/** If the template function returns null no template is injected */
template: ((el: HTMLElement) => string | null);
initialize: (el: HTMLElement, data: ValueType) => Scope;
/** array of attribiute names to force parse attributes as static (primitive) values */
static?: string[];
/** array of attribiute names to auto bind attributes to the scope */
bind?: string[];
// extension options
binders?: IBinders<any>;
formatters?: IFormatters;
components?: IComponents;
adapters?: IAdapters;
// other options
prefix?: string;
preloadData?: boolean;
rootInterface?: string;
templateDelimiters?: Array<string>;
/**
* If you want to save custom data in your binder logic
*/
[key: string]: any;
handler?: (this: any, context: any, ev: Event, binding: IBindable) => void;
}
export interface IComponents {
[name: string]: IClassicComponent<any> | typeof RibaComponent;
}
export interface IComponentWrapperResult<ValueType> extends IClassicComponent<ValueType> {
name: string;
}
export type ComponentWrapper<ValueType> = (...deps: any[]) => IComponentWrapperResult<ValueType>;
export class ComponentService {

@@ -52,0 +6,0 @@

@@ -1,21 +0,7 @@

import Debug from 'debug';
import { Debug } from '../modules';
import { IFormatter, IModuleFormatters, IModuleFormatterWrapper } from '../interfaces/formatter';
import { Utils } from './utils';
export interface IOneWayFormatter {
(val: any, ...args: any[]): any;
read?: (result: string, ...processedArgs: string[]) => void;
}
export interface IOneTwoFormatter {
read: (result: string, ...processedArgs: string[]) => void;
publish: (result: string, ...processedArgs: string[]) => void;
}
export type IFormatter = IOneWayFormatter | IOneTwoFormatter;
export interface IFormatters {
[name: string]: IFormatter;
}
export class FormatterService {
private formatters: IFormatters;
private formatters: IModuleFormatters;
private debug = Debug('formatters:FormatterService');

@@ -26,3 +12,3 @@

*/
constructor(formatters: IFormatters) {
constructor(formatters: IModuleFormatters) {
this.formatters = formatters;

@@ -33,17 +19,17 @@ }

* Regist a formatter with his name
* @param component
* @param formatter
* @param name
*/
public regist(component: IFormatter, name?: string): IFormatters {
public regist(formatter: IFormatter, name?: string): IModuleFormatters {
if (!name) {
if (component.hasOwnProperty('constructor')) {
name = component.constructor.name;
if (formatter.hasOwnProperty('constructor')) {
name = formatter.constructor.name;
}
if (component.hasOwnProperty('name')) {
name = (component as any).name;
if (formatter.hasOwnProperty('name')) {
name = (formatter as any).name;
}
}
this.debug('name', name, component);
this.debug('name', name, formatter);

@@ -55,3 +41,3 @@ if (!name) {

// if Binder<any>
this.formatters[name] = component;
this.formatters[name] = formatter;
return this.formatters;

@@ -64,10 +50,18 @@ }

*/
public regists(formatters: IFormatters): IFormatters {
for (const name in formatters) {
if (formatters.hasOwnProperty(name)) {
this.regist(formatters[name], name);
public regists(formatters: IModuleFormatterWrapper[] | IModuleFormatters): IModuleFormatters {
if (Utils.isArray(formatters)) {
for (let index = 0; index < formatters.length; index++) {
const formatterWrapper = (formatters as IModuleFormatterWrapper[])[index];
this.regist((formatterWrapper as IModuleFormatterWrapper).formatter, (formatterWrapper as IModuleFormatterWrapper).name);
}
}
if (Utils.isObject(formatters)) {
for (const name in formatters) {
if (formatters.hasOwnProperty(name)) {
this.regist((formatters as IModuleFormatters)[name], name);
}
}
}
return this.formatters;
}
}

@@ -1,8 +0,12 @@

import { IViewOptions, Riba } from './riba';
import { Binder, ITwoWayBinder } from './services/binder.service';
import { Binding, IBindable } from './binding';
import { Riba } from './riba';
import {
Binder,
ITwoWayBinder,
IViewOptions,
} from './interfaces';
import { Binding } from './binding';
import { ComponentService} from './services/component.service';
import { ComponentBinding, IBoundElement } from './components/component-binding';
import { parseNode, parseDeclaration } from './parsers';
import Debug from 'debug';
import { Debug } from './modules/debug.module';
import { RibaComponentClass } from './components/riba-component-class';

@@ -9,0 +13,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc