Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of can-util #50

Merged
merged 1 commit into from
Jul 5, 2018
Merged
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
6 changes: 5 additions & 1 deletion can-validate-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* jshint asi: false */
var Map = require("can-map");
var isEmptyObject = require("can-util/js/is-empty-object/is-empty-object");
var canReflect = require("can-reflect");
var QUnit = require("steal-qunit");

require("can-map-define");
Expand Down Expand Up @@ -34,6 +34,10 @@ var ValidatedMap = Map.extend({
}
});

var isEmptyObject = function(value) {
return canReflect.size(value) === 0;
};

QUnit.module("Map Validate Plugin");

QUnit.test("when validateOnInit is not set, it should not run validation",function(){
Expand Down
4 changes: 2 additions & 2 deletions can-validate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
var dev = require("can-util/js/dev/dev");
var namespace = require("can-util/namespace");
var dev = require("can-log/dev/dev");
var namespace = require("can-namespace");

// add methods to can
var Validate = {
Expand Down
17 changes: 10 additions & 7 deletions map/validate/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
var assign = require("can-assign");

var Map = require("can-map");
var each = require("can-util/js/each/each");
var isEmptyObject = require("can-util/js/is-empty-object/is-empty-object");
var canReflect = require("can-reflect");
var validate = require("can-validate-legacy");
var compute = require("can-compute");

Expand All @@ -18,6 +17,10 @@ var deepAssign = function() {
return out;
};

var isEmptyObject = function(value) {
return canReflect.size(value) === 0;
};

var proto = Map.prototype;
var oldSet = proto.__set;
var ErrorsObj;
Expand All @@ -31,7 +34,7 @@ var resolveComputes = function (itemObj, opts) {
var processedObj = {};

// Loop through each validation option
each(opts, function (item, key) {
canReflect.eachKey(opts, function (item, key) {
var actualOpts = item;
if (typeof item === "function") {
// create compute and add it to computes array
Expand Down Expand Up @@ -142,7 +145,7 @@ assign(Map.prototype, {
_initValidation: function () {
var self = this;
var validateCache = getValidateFromCache.call(this);
each(this.define, function (props, key) {
canReflect.eachKey(this.define, function (props, key) {
if (props.validate && !validateCache[key]) {
initProperty.call(self, key, self[key]);
}
Expand Down Expand Up @@ -173,7 +176,7 @@ assign(Map.prototype, {
var self = this;

// Loop through validate options
each(this.define, function (value, key) {
canReflect.eachKey(this.define, function (value, key) {
if (value.validate) {
processedOpts[key] = resolveComputes({key: key, value: self.attr(key)}, validateOpts[key]);
}
Expand Down Expand Up @@ -251,7 +254,7 @@ assign(Map.prototype, {
var self = this;

// Loop through each validation option
each(opts, function (item, key) {
canReflect.eachKey(opts, function (item, key) {
processedObj[key] = item;
if (typeof item === "function") {
// create compute and add it to computes array
Expand All @@ -264,7 +267,7 @@ assign(Map.prototype, {
// Using the computes array, create necessary listeners
// We do this afterwards instead of inline so we can have access
// to the final set of validation options.
each(computes, function (item) {
canReflect.each(computes, function (item) {
item.compute.bind("change", function () {
itemObj.value = self.attr(itemObj.key);
self._validateOne(itemObj, processedObj);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
},
"dependencies": {
"can-assign": "^1.1.1",
"can-util": "^3.9.0",
"can-log": "<2.0.0",
"can-namespace": "<2.0.0",
"can-reflect": "^1.0.0",
"validate.js": "<0.12.0"
}
}