From 0a7cfab30357173001370aaad9b08f532c66d00d Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Thu, 22 Jun 2017 22:37:10 -0500 Subject: [PATCH] 3.3.0 --- dist/amd/can-view-model.js | 41 +++++++++ dist/cjs/can-view-model.js | 39 +++++++++ dist/global/can-view-model.js | 156 ++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 dist/amd/can-view-model.js create mode 100644 dist/cjs/can-view-model.js create mode 100644 dist/global/can-view-model.js diff --git a/dist/amd/can-view-model.js b/dist/amd/can-view-model.js new file mode 100644 index 0000000..7352809 --- /dev/null +++ b/dist/amd/can-view-model.js @@ -0,0 +1,41 @@ +/*can-view-model@3.3.0-pre.5#can-view-model*/ +define(function (require, exports, module) { + 'use strict'; + var domData = require('can-util/dom/data'); + var SimpleMap = require('can-simple-map'); + var types = require('can-types'); + var ns = require('can-namespace'); + var getDocument = require('can-util/dom/document'); + var isArrayLike = require('can-util/js/is-array-like'); + var canReflect = require('can-reflect'); + module.exports = ns.viewModel = function (el, attr, val) { + var scope; + if (typeof el === 'string') { + el = getDocument().querySelector(el); + } else if (isArrayLike(el) && !el.nodeType) { + el = el[0]; + } + if (canReflect.isObservableLike(attr) && canReflect.isMapLike(attr)) { + return domData.set.call(el, 'viewModel', attr); + } + scope = domData.get.call(el, 'viewModel'); + if (!scope) { + scope = types.DefaultMap ? new types.DefaultMap() : new SimpleMap(); + domData.set.call(el, 'viewModel', scope); + } + switch (arguments.length) { + case 0: + case 1: + return scope; + case 2: + return 'attr' in scope ? scope.attr(attr) : scope[attr]; + default: + if ('attr' in scope) { + scope.attr(attr, val); + } else { + scope[attr] = val; + } + return el; + } + }; +}); \ No newline at end of file diff --git a/dist/cjs/can-view-model.js b/dist/cjs/can-view-model.js new file mode 100644 index 0000000..14d360a --- /dev/null +++ b/dist/cjs/can-view-model.js @@ -0,0 +1,39 @@ +/*can-view-model@3.3.0-pre.5#can-view-model*/ +'use strict'; +var domData = require('can-util/dom/data/data'); +var SimpleMap = require('can-simple-map'); +var types = require('can-types'); +var ns = require('can-namespace'); +var getDocument = require('can-util/dom/document/document'); +var isArrayLike = require('can-util/js/is-array-like/is-array-like'); +var canReflect = require('can-reflect'); +module.exports = ns.viewModel = function (el, attr, val) { + var scope; + if (typeof el === 'string') { + el = getDocument().querySelector(el); + } else if (isArrayLike(el) && !el.nodeType) { + el = el[0]; + } + if (canReflect.isObservableLike(attr) && canReflect.isMapLike(attr)) { + return domData.set.call(el, 'viewModel', attr); + } + scope = domData.get.call(el, 'viewModel'); + if (!scope) { + scope = types.DefaultMap ? new types.DefaultMap() : new SimpleMap(); + domData.set.call(el, 'viewModel', scope); + } + switch (arguments.length) { + case 0: + case 1: + return scope; + case 2: + return 'attr' in scope ? scope.attr(attr) : scope[attr]; + default: + if ('attr' in scope) { + scope.attr(attr, val); + } else { + scope[attr] = val; + } + return el; + } +}; \ No newline at end of file diff --git a/dist/global/can-view-model.js b/dist/global/can-view-model.js new file mode 100644 index 0000000..a569a27 --- /dev/null +++ b/dist/global/can-view-model.js @@ -0,0 +1,156 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval){ // jshint ignore:line + var origDefine = global.define; + + var get = function(name){ + var parts = name.split("."), + cur = global, + i; + for(i = 0 ; i < parts.length; i++){ + if(!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val){ + var parts = name.split("."), + cur = global, + i, part, next; + for(i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if(!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod){ + if(!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, "default": true }; + for(var p in mod) { + if(!esProps[p]) return false; + } + return true; + }; + var modules = (global.define && global.define.modules) || + (global._define && global._define.modules) || {}; + var ourDefine = global.define = function(moduleName, deps, callback){ + var module; + if(typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for(i =0; i < deps.length; i++) { + args.push( exports[deps[i]] ? get(exports[deps[i]]) : ( modules[deps[i]] || get(deps[i]) ) ); + } + // CJS has no dependencies but 3 callback arguments + if(!deps.length && callback.length) { + module = { exports: {} }; + var require = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args.push(require, module.exports, module); + } + // Babel uses the exports and module object. + else if(!args[0] && deps[0] === "exports") { + module = { exports: {} }; + args[0] = module.exports; + if(deps[1] === "module") { + args[1] = module; + } + } else if(!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if(globalExport && !get(globalExport)) { + if(useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }; + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function(){ + // shim for @@global-helpers + var noop = function(){}; + return { + get: function(){ + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load){ + doEval(__load.source, global); + } + }; + }); +} +)({},window,function(__$source__, __$global__) { // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); +} +) +/*can-view-model@3.3.0-pre.5#can-view-model*/ +define('can-view-model', function (require, exports, module) { + 'use strict'; + var domData = require('can-util/dom/data/data'); + var SimpleMap = require('can-simple-map'); + var types = require('can-types'); + var ns = require('can-namespace'); + var getDocument = require('can-util/dom/document/document'); + var isArrayLike = require('can-util/js/is-array-like/is-array-like'); + var canReflect = require('can-reflect'); + module.exports = ns.viewModel = function (el, attr, val) { + var scope; + if (typeof el === 'string') { + el = getDocument().querySelector(el); + } else if (isArrayLike(el) && !el.nodeType) { + el = el[0]; + } + if (canReflect.isObservableLike(attr) && canReflect.isMapLike(attr)) { + return domData.set.call(el, 'viewModel', attr); + } + scope = domData.get.call(el, 'viewModel'); + if (!scope) { + scope = types.DefaultMap ? new types.DefaultMap() : new SimpleMap(); + domData.set.call(el, 'viewModel', scope); + } + switch (arguments.length) { + case 0: + case 1: + return scope; + case 2: + return 'attr' in scope ? scope.attr(attr) : scope[attr]; + default: + if ('attr' in scope) { + scope.attr(attr, val); + } else { + scope[attr] = val; + } + return el; + } + }; +}); +/*[global-shim-end]*/ +(function(){ // jshint ignore:line + window._define = window.define; + window.define = window.define.orig; +} +)(); \ No newline at end of file