Skip to content

Commit 42c7d83

Browse files
committed
1.0.0
1 parent 28c8f8b commit 42c7d83

File tree

3 files changed

+278
-0
lines changed

3 files changed

+278
-0
lines changed

dist/amd/can-simple-observable.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*can-simple-observable@0.0.0#can-simple-observable*/
2+
define([
3+
'require',
4+
'exports',
5+
'module',
6+
'can-reflect',
7+
'can-event/batch',
8+
'can-observation',
9+
'can-cid'
10+
], function (require, exports, module) {
11+
var canReflect = require('can-reflect');
12+
var canBatch = require('can-event/batch');
13+
var Observation = require('can-observation');
14+
var CID = require('can-cid');
15+
module.exports = function reflectiveValue(initialValue) {
16+
var value = initialValue;
17+
var handlers = [];
18+
var fn = function (newValue) {
19+
if (arguments.length) {
20+
value = newValue;
21+
handlers.forEach(function (handler) {
22+
canBatch.queue([
23+
handler,
24+
fn,
25+
[newValue]
26+
]);
27+
}, this);
28+
} else {
29+
Observation.add(fn);
30+
return value;
31+
}
32+
};
33+
CID(fn);
34+
canReflect.assignSymbols(fn, {
35+
'can.onValue': function (handler) {
36+
handlers.push(handler);
37+
},
38+
'can.offValue': function (handler) {
39+
var index = handlers.indexOf(handler);
40+
handlers.splice(index, 1);
41+
},
42+
'can.setValue': function (newValue) {
43+
return fn(newValue);
44+
},
45+
'can.getValue': function () {
46+
return fn();
47+
}
48+
});
49+
return fn;
50+
};
51+
});

dist/cjs/can-simple-observable.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*can-simple-observable@0.0.0#can-simple-observable*/
2+
var canReflect = require('can-reflect');
3+
var canBatch = require('can-event/batch/batch');
4+
var Observation = require('can-observation');
5+
var CID = require('can-cid');
6+
module.exports = function reflectiveValue(initialValue) {
7+
var value = initialValue;
8+
var handlers = [];
9+
var fn = function (newValue) {
10+
if (arguments.length) {
11+
value = newValue;
12+
handlers.forEach(function (handler) {
13+
canBatch.queue([
14+
handler,
15+
fn,
16+
[newValue]
17+
]);
18+
}, this);
19+
} else {
20+
Observation.add(fn);
21+
return value;
22+
}
23+
};
24+
CID(fn);
25+
canReflect.assignSymbols(fn, {
26+
'can.onValue': function (handler) {
27+
handlers.push(handler);
28+
},
29+
'can.offValue': function (handler) {
30+
var index = handlers.indexOf(handler);
31+
handlers.splice(index, 1);
32+
},
33+
'can.setValue': function (newValue) {
34+
return fn(newValue);
35+
},
36+
'can.getValue': function () {
37+
return fn();
38+
}
39+
});
40+
return fn;
41+
};
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*[global-shim-start]*/
2+
(function(exports, global, doEval) {
3+
// jshint ignore:line
4+
var origDefine = global.define;
5+
6+
var get = function(name) {
7+
var parts = name.split("."),
8+
cur = global,
9+
i;
10+
for (i = 0; i < parts.length; i++) {
11+
if (!cur) {
12+
break;
13+
}
14+
cur = cur[parts[i]];
15+
}
16+
return cur;
17+
};
18+
var set = function(name, val) {
19+
var parts = name.split("."),
20+
cur = global,
21+
i,
22+
part,
23+
next;
24+
for (i = 0; i < parts.length - 1; i++) {
25+
part = parts[i];
26+
next = cur[part];
27+
if (!next) {
28+
next = cur[part] = {};
29+
}
30+
cur = next;
31+
}
32+
part = parts[parts.length - 1];
33+
cur[part] = val;
34+
};
35+
var useDefault = function(mod) {
36+
if (!mod || !mod.__esModule) return false;
37+
var esProps = { __esModule: true, default: true };
38+
for (var p in mod) {
39+
if (!esProps[p]) return false;
40+
}
41+
return true;
42+
};
43+
44+
var hasCjsDependencies = function(deps) {
45+
return (
46+
deps[0] === "require" && deps[1] === "exports" && deps[2] === "module"
47+
);
48+
};
49+
50+
var modules =
51+
(global.define && global.define.modules) ||
52+
(global._define && global._define.modules) ||
53+
{};
54+
var ourDefine = (global.define = function(moduleName, deps, callback) {
55+
var module;
56+
if (typeof deps === "function") {
57+
callback = deps;
58+
deps = [];
59+
}
60+
var args = [],
61+
i;
62+
for (i = 0; i < deps.length; i++) {
63+
args.push(
64+
exports[deps[i]]
65+
? get(exports[deps[i]])
66+
: modules[deps[i]] || get(deps[i])
67+
);
68+
}
69+
// CJS has no dependencies but 3 callback arguments
70+
if (hasCjsDependencies(deps) || (!deps.length && callback.length)) {
71+
module = { exports: {} };
72+
args[0] = function(name) {
73+
return exports[name] ? get(exports[name]) : modules[name];
74+
};
75+
args[1] = module.exports;
76+
args[2] = module;
77+
} else if (!args[0] && deps[0] === "exports") {
78+
// Babel uses the exports and module object.
79+
module = { exports: {} };
80+
args[0] = module.exports;
81+
if (deps[1] === "module") {
82+
args[1] = module;
83+
}
84+
} else if (!args[0] && deps[0] === "module") {
85+
args[0] = { id: moduleName };
86+
}
87+
88+
global.define = origDefine;
89+
var result = callback ? callback.apply(null, args) : undefined;
90+
global.define = ourDefine;
91+
92+
// Favor CJS module.exports over the return value
93+
result = module && module.exports ? module.exports : result;
94+
modules[moduleName] = result;
95+
96+
// Set global exports
97+
var globalExport = exports[moduleName];
98+
if (globalExport && !get(globalExport)) {
99+
if (useDefault(result)) {
100+
result = result["default"];
101+
}
102+
set(globalExport, result);
103+
}
104+
});
105+
global.define.orig = origDefine;
106+
global.define.modules = modules;
107+
global.define.amd = true;
108+
ourDefine("@loader", [], function() {
109+
// shim for @@global-helpers
110+
var noop = function() {};
111+
return {
112+
get: function() {
113+
return { prepareGlobal: noop, retrieveGlobal: noop };
114+
},
115+
global: global,
116+
__exec: function(__load) {
117+
doEval(__load.source, global);
118+
}
119+
};
120+
});
121+
})(
122+
{},
123+
typeof self == "object" && self.Object == Object ? self : window,
124+
function(__$source__, __$global__) {
125+
// jshint ignore:line
126+
eval("(function() { " + __$source__ + " \n }).call(__$global__);");
127+
}
128+
);
129+
130+
/*can-simple-observable@0.0.0#can-simple-observable*/
131+
define('can-simple-observable', [
132+
'require',
133+
'exports',
134+
'module',
135+
'can-reflect',
136+
'can-event/batch/batch',
137+
'can-observation',
138+
'can-cid'
139+
], function (require, exports, module) {
140+
var canReflect = require('can-reflect');
141+
var canBatch = require('can-event/batch/batch');
142+
var Observation = require('can-observation');
143+
var CID = require('can-cid');
144+
module.exports = function reflectiveValue(initialValue) {
145+
var value = initialValue;
146+
var handlers = [];
147+
var fn = function (newValue) {
148+
if (arguments.length) {
149+
value = newValue;
150+
handlers.forEach(function (handler) {
151+
canBatch.queue([
152+
handler,
153+
fn,
154+
[newValue]
155+
]);
156+
}, this);
157+
} else {
158+
Observation.add(fn);
159+
return value;
160+
}
161+
};
162+
CID(fn);
163+
canReflect.assignSymbols(fn, {
164+
'can.onValue': function (handler) {
165+
handlers.push(handler);
166+
},
167+
'can.offValue': function (handler) {
168+
var index = handlers.indexOf(handler);
169+
handlers.splice(index, 1);
170+
},
171+
'can.setValue': function (newValue) {
172+
return fn(newValue);
173+
},
174+
'can.getValue': function () {
175+
return fn();
176+
}
177+
});
178+
return fn;
179+
};
180+
});
181+
/*[global-shim-end]*/
182+
(function(global) { // jshint ignore:line
183+
global._define = global.define;
184+
global.define = global.define.orig;
185+
}
186+
)(typeof self == "object" && self.Object == Object ? self : window);

0 commit comments

Comments
 (0)