Skip to content

Commit

Permalink
update type-checkers build
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiuz committed Sep 29, 2018
1 parent 3ef6e8c commit 15b355e
Show file tree
Hide file tree
Showing 41 changed files with 1,669 additions and 3,676 deletions.
1,231 changes: 714 additions & 517 deletions dist/type-checkers.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/type-checkers.js.map

Large diffs are not rendered by default.

804 changes: 1 addition & 803 deletions dist/type-checkers.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/type-checkers.min.js.map

Large diffs are not rendered by default.

46 changes: 35 additions & 11 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,33 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
<base href="/">
<script src="dist/type-checkers.min.js"></script>
<script src="type-checkers.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
const getTypeOf = (value) => {
const type = typeof value;

if (type === 'object' && value instanceof Array) {
return 'array';
}

return type;
};

TypeCheckers.setDefaultTypeChecker({
init(target, errorReporter, data) {
console.log('init:', target);
return {};
init() {
},
getProperty(target, names, value, data) {
console.log('get:', target, names, value, data);
},
setProperty(target, names, value, data) {
console.log('set:', target, names, value, data);

setProperty(target, names, value) {
const { lastName } = names;

const currentType = getTypeOf(target[lastName]);
const newType = getTypeOf(value);

if (currentType !== 'undefined' && currentType !== newType) {
console.error(`${names} value "${value}" is of type "${newType}" instead of "${currentType}"`);
}
}
});

Expand Down Expand Up @@ -55,11 +67,23 @@
},
};

const typeChecked = TypeCheckers.wrapDeep(myObj);
const { wrap, wrapDeep, getTargetInfo } = TypeCheckers;

const typeChecked = wrap(myObj, { name: 'myObj' }, { set: true });

console.log(getTargetInfo(typeChecked));

Object.assign(typeChecked, { val1: 'abc', val2: 123, val3: 456, list: '1,2,3' });

// this code will work as intended, but type errors should spam
/*
typeChecked.val1 = 'abc';
typeChecked.val2 = { shouldBeString: true };
typeChecked.child.val2 = { shouldBeString: true };
typeChecked.list = '1,2,3';
typeChecked.list = [1, 2, 3, 4];
typeChecked.list[2] = '3';
typeChecked.list[0] = true;
*/
/*
// when indexed typing enabled
TypeCheckers.PrimitiveTypeChecker.setIndexValueTypeBy(typeChecked.list, 0);
Expand Down
Loading

0 comments on commit 15b355e

Please sign in to comment.