Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Update DI #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {Provide} from 'di';
import {Provide, Inject} from 'di';
import {ChangeEventConfig} from 'templating';
import {XTagsEventConfig} from './xtags_event_config';

// config for DI
@Inject
@Provide(ChangeEventConfig)
export function AppChangeEventConfig() {
var res = [];
res.push(...ChangeEventConfig());
res.push(...XTagsEventConfig());
res.push(...ChangeEventConfig);
res.push(...XTagsEventConfig);
return res;
}

Expand Down
8 changes: 3 additions & 5 deletions examples/xtags_event_config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export function XTagsEventConfig() {
return [{
nodeName: 'x-toggle', events: ['change'], properties: ()=>['checked']
}];
}
export var XTagsEventConfig = [{
nodeName: 'x-toggle', events: ['change'], properties: ()=>['checked']
}];
14 changes: 5 additions & 9 deletions src/compiler/selector_config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {Inject} from 'di'

export function SelectorConfig() {
return {
interpolationRegex: /{{(.*?)}}/g,
bindAttrRegex: /bind-(.+)/,
eventAttrRegex: /on-(.+)/,
};
}
export var SelectorConfig = {
interpolationRegex: /{{(.*?)}}/g,
bindAttrRegex: /bind-(.+)/,
eventAttrRegex: /on-(.+)/,
};
14 changes: 6 additions & 8 deletions src/event_handler.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {Inject} from 'di';

export function ChangeEventConfig() {
return [
{nodeName: 'input', events: ['input', 'keypress', 'change'], properties: ()=>['value', 'valueAsDate', 'valueAsNumber']},
{nodeName: 'textarea', events: ['input', 'keypress', 'change'], properties: ()=>['value']},
{nodeName: 'select', events: ['change'], properties: ()=>['value']},
{nodeName: '*', events: ['propchange'], properties: (event) => event.properties}
];
}
export var ChangeEventConfig = [
{nodeName: 'input', events: ['input', 'keypress', 'change'], properties: ()=>['value', 'valueAsDate', 'valueAsNumber']},
{nodeName: 'textarea', events: ['input', 'keypress', 'change'], properties: ()=>['value']},
{nodeName: 'select', events: ['change'], properties: ()=>['value']},
{nodeName: '*', events: ['propchange'], properties: (event) => event.properties}
];

export class EventHandler {
@Inject(ChangeEventConfig)
Expand Down
3 changes: 3 additions & 0 deletions src/global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {Inject} from 'di';

@Inject
export function Global() {
return window;
}
3 changes: 3 additions & 0 deletions src/loader/document_loader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {Inject} from 'di';

@Inject
export function DocumentLoader() {
throw new Error('Abstract function');
}
Expand Down
20 changes: 9 additions & 11 deletions src/util/annotation_provider.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export function AnnotationProvider() {
return function(clazz:Function, annotationType:Function) {
var annotations = clazz.annotations || [];
var res;
annotations.forEach(function(annotation) {
if (annotation instanceof annotationType) {
res = annotation;
}
});
return res;
}
export function AnnotationProvider(clazz:Function, annotationType:Function) {
var annotations = clazz.annotations || [];
var res;
annotations.forEach(function(annotation) {
if (annotation instanceof annotationType) {
res = annotation;
}
});
return res;
}
3 changes: 2 additions & 1 deletion src/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NodeContainer} from './types';
import {LinkedList, LinkedListItem} from './util/linked_list';
import {Injector} from 'di';
import {Injector, Inject} from 'di';

import {WatchParser, Parser} from 'expressionist';
import {Parser} from 'expressionist';
Expand All @@ -14,6 +14,7 @@ import { NgNode, ArrayOfNgNode } from './ng_node';
* Views are added to the ViewPort by the template directives
* such as ng-if and ng-repeat.
*/
@Inject
export class View extends LinkedListItem {
constructor(parentView:View, container:NodeContainer, injector:Injector, executionContext:Object = {}) {
super();
Expand Down