Skip to content

Commit

Permalink
Merge pull request #4 from InDIOS/development
Browse files Browse the repository at this point in the history
Bump to version 0.0.4
  • Loading branch information
InDIOS authored Oct 31, 2018
2 parents 84e0ca0 + d9a5110 commit c1ed2b7
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trebor-tools",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 5 additions & 7 deletions src/baseComp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ _$assign(_$BaseComponent[PROP_MAP.h], {
}
});

export function _$Ctor(moduleName: string, tpl: Function, options: Object) {
const ctor: ComponentConstructor = <any>{
[moduleName](_$attrs, _$parent) {
_$BaseComponent.call(this, _$attrs, tpl, options, _$parent);
!_$parent && this.$create();
}
}[moduleName];
export function _$Ctor(tpl: Function, options: Object) {
const ctor: ComponentConstructor = <any>function (_$attrs, _$parent) {
_$BaseComponent.call(this, _$attrs, tpl, options, _$parent);
!_$parent && this.$create();
};
ctor.plugin = (fn: PluginFn, options?: ObjectLike<any>) => {
TPS.push({ options, fn });
};
Expand Down
31 changes: 15 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { _$Ctor } from './baseComp';
import {
_$removeChild, _$isType, _$noop, _$componentUpdate, _$bindClasses,
_$bindStyle, _$forLoop, _$each, _$bindBooleanAttr, _$setReference, _$isKey,
_$textUpdate, _$tagUpdate, _$removeReference, _$destroyComponent, _$setElements,
_$conditionalUpdate, _$emptyElse, _$htmlUpdate, _$addChild, _$toString, _$bindUpdate,
_$removeChild, _$isType, _$noop, _$componentUpdate, _$bindClasses, _$bindStyle, _$forLoop,
_$destroyComponent, _$setElements, _$conditionalUpdate, _$emptyElse, _$htmlUpdate, _$addChild,
_$each, _$bindBooleanAttr, _$setReference, _$isKey, _$textUpdate, _$tagUpdate, _$removeReference,
_$toString, _$bindUpdate, _$emptySlot, _$appendToSlot, _$declareSlots
} from './utilities';
import {
_$el, _$svg, _$text, _$comment, _$setAttr,
_$removeStyle, _$getValue, _$bindMultiSelect,
_$select, _$docFragment, _$append, _$assignEl, _$removeEl,
_$getAttr, _$addListener, _$updateListener, _$removeListener, _$insertStyle,
_$bindGroup, _$updateMultiSelect
_$select, _$docFragment, _$append, _$assignEl, _$removeEl, _$getAttr, _$addListener,
_$updateListener, _$removeListener, _$insertStyle, _$bindGroup, _$updateMultiSelect,
_$el, _$svg, _$text, _$comment, _$setAttr, _$removeStyle, _$getValue, _$bindMultiSelect,
} from './dom';
import { _$Ctor } from './baseComp';

export {
_$removeChild, _$bindGroup, _$emptyElse, _$Ctor, _$bindMultiSelect, _$setAttr,
_$removeEl, _$assignEl, _$el, _$bindStyle, _$forLoop, _$each, _$insertStyle, _$removeStyle,
_$getAttr, _$addListener, _$updateListener, _$removeListener, _$bindClasses, _$destroyComponent,
_$svg, _$noop, _$toString, _$setReference, _$isType, _$isKey, _$select, _$docFragment, _$append,
_$updateMultiSelect, _$componentUpdate, _$htmlUpdate, _$tagUpdate, _$bindBooleanAttr, _$removeReference,
_$addChild, _$textUpdate, _$getValue, _$text, _$conditionalUpdate, _$bindUpdate, _$comment, _$setElements
_$bindUpdate, _$comment, _$setElements, _$emptySlot, _$appendToSlot, _$declareSlots,
_$updateMultiSelect, _$componentUpdate, _$htmlUpdate, _$tagUpdate, _$bindBooleanAttr,
_$removeReference, _$addChild, _$textUpdate, _$getValue, _$text, _$conditionalUpdate,
_$noop, _$toString, _$setReference, _$isType, _$isKey, _$select, _$docFragment, _$append,
_$removeChild, _$bindGroup, _$emptyElse, _$Ctor, _$bindMultiSelect, _$setAttr, _$removeEl,
_$assignEl, _$el, _$bindStyle, _$forLoop, _$each, _$insertStyle, _$removeStyle, _$getAttr,
_$addListener, _$updateListener, _$removeListener, _$bindClasses, _$destroyComponent, _$svg,
};
12 changes: 11 additions & 1 deletion src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PROP_MAP } from './constants';
import { _$toArgs, _$List } from './list';
import { _$el, _$getAttr, _$setAttr, _$select, _$assignEl, _$removeEl } from './dom';
import { _$el, _$getAttr, _$setAttr, _$select, _$assignEl, _$removeEl, _$docFragment, _$append } from './dom';

function _$toLowerCase(str: string) {
return str.toLowerCase();
Expand Down Expand Up @@ -172,6 +172,16 @@ export function _$emptyElse() {
export function _$isKey(event: KeyboardEvent, key: string) {
return _$toLowerCase(event.key) === key || !!event[`${key}Key`];
}
export function _$emptySlot(inst: Component, slot: string) {
let slots = inst.$slots;
return slots[slot] && !slots[slot].hasChildNodes() ? (slots[slot] = _$docFragment()) : null;
}
export function _$appendToSlot(slots: ObjectLike<DocumentFragment>, slot: string, el: HTMLElement) {
!slots[slot].firstChild && _$append(<any>slots[slot], el);
}
export function _$declareSlots($slots: ObjectLike<DocumentFragment>, slots: string[]) {
_$each(slots, slot => { $slots[slot] = _$docFragment(); });
}
export function _$bindClasses(value: string | ObjectLike<boolean> | (string | ObjectLike<boolean>)[]) {
let classes = '';
if (_$isString(value)) {
Expand Down
13 changes: 13 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
"semicolon": [
true, "always"
],
"triple-equals": [
true, "allow-null-check"
],
"quotemark": [
true, "single"
]
}
}
25 changes: 19 additions & 6 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ interface DirectiveOptions {
modifiers: ObjectLike<boolean>;
}

interface ComponentOptions {
model: ObjectLike<any>;
attrs: string[] | ObjectLike<AttrDefinition>;
filters: ObjectLike<(...args: any[]) => any>;
children: ObjectLike<ComponentConstructor>;
directives: ObjectLike<DirectiveDefinition>;
interface ComponentOptions extends ComponentHooks {
model?: ObjectLike<any>;
attrs?: string[] | ObjectLike<AttrDefinition>;
filters?: ObjectLike<(...args: any[]) => any>;
children?: ObjectLike<ComponentConstructor>;
directives?: ObjectLike<DirectiveDefinition>;
}

interface ComponentTemplate {
Expand All @@ -43,6 +43,19 @@ interface ComponentTemplate {
$destroy(): void;
}

interface ComponentHooks {
willCreate?(this: Component): void;
willMount?(this: Component): void;
willUpdate?(this: Component): void;
willUnmount?(this: Component): void;
willDestroy?(this: Component): void;
didCreate?(this: Component): void;
didMount?(this: Component): void;
didUpdate?(this: Component): void;
didUnmount?(this: Component): void;
didDestroy?(this: Component): void;
}

interface Component extends ComponentTemplate {
$parent: Component;
$parentEl: HTMLElement;
Expand Down

0 comments on commit c1ed2b7

Please sign in to comment.