Skip to content

Commit

Permalink
Merge pull request #343 from meteor/release-2.6
Browse files Browse the repository at this point in the history
Release 2.6
  • Loading branch information
denihs authored Apr 13, 2022
2 parents e2babd7 + 1c31498 commit a8dab83
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 143 deletions.
21 changes: 21 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## v2.6.0, 2022-April-13

* [#330](https://github.com/meteor/blaze/pull/330) Removed deprecated APIs from before Meteor 1.0
* This is potentially breaking, especially for old packages and apps.
* `blaze-html-templates@2.0.0`
* Dependency on `ui` and `spacebars` package has been removed
* `spacebars@1.3.0`
* `Spacebars.TemplateWith` has been removed, please use `Blaze._TemplateWith` if you need it.
* `blaze@2.6.0`
* `Blaze.InOuterTemplateScope` has been removed, if you need it, you can use `Blaze._InOuterTemplateScope`
* `templating-runtime@1.6.0`
* `Template.__define__` has been removed
* `UI.body` has been removed, you should be using `Template.body`
* `Template.__body__` has been removed, you should be using `Template.body`
* `Template.__body__.__contentParts` has been removed, you should be using `Template.body.contentViews`
* `Template.__body__.__instantiate` has been removed, you should be using `Template.body.renderToDocument`
* [#341](https://github.com/meteor/blaze/pull/341) Add support for arbitrary iterables in #each templates
* [#358](https://github.com/meteor/blaze/pull/358) Make Template.contentBlock consistent with/out data provided
* [#359](https://github.com/meteor/blaze/pull/359) Underscore has been removed from observe sequence
* Updated testing dependencies

## v2.5.0, 2021-June-5

* [#331](https://github.com/meteor/blaze/pull/331) Remove underscore and all of its methods in the code
Expand Down
6 changes: 3 additions & 3 deletions packages/blaze-hot/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'blaze-hot',
summary: "Update files using Blaze's API with HMR",
version: '1.1.0',
version: '1.1.1',
git: 'https://github.com/meteor/blaze.git',
documentation: null,
debugOnly: true
Expand All @@ -10,8 +10,8 @@ Package.describe({
Package.onUse(function (api) {
api.use('modules@0.16.0');
api.use('ecmascript@0.15.1');
api.use('blaze@2.5.0');
api.use('templating-runtime@1.4.0');
api.use('blaze@2.6.0');
api.use('templating-runtime@1.6.0');
api.use('hot-module-replacement@0.2.0', { weak: true });

api.addFiles('hot.js', 'client');
Expand Down
8 changes: 1 addition & 7 deletions packages/blaze-html-templates/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'blaze-html-templates',
summary: "Compile HTML templates into reactive UI with Meteor Blaze",
version: '1.2.1',
version: '2.0.0',
git: 'https://github.com/meteor/blaze.git'
});

Expand All @@ -10,12 +10,6 @@ Package.onUse(function(api) {
// A library for reactive user interfaces
'blaze@2.5.0',

// The following packages are basically empty shells that just exist to
// satisfy code checking for the existence of a package. Rest assured that
// they are not adding any bloat to your bundle.
'ui@1.0.13', // XXX COMPAT WITH PACKAGES BUILT FOR 0.9.0.
'spacebars@1.2.0', // XXX COMPAT WITH PACKAGES BUILT FOR 0.9.0

// Compile .html files into Blaze reactive views
'templating@1.4.1'
]);
Expand Down
6 changes: 3 additions & 3 deletions packages/blaze-tools/package.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package.describe({
name: 'blaze-tools',
summary: "Compile-time tools for Blaze",
version: '1.1.2',
version: '1.1.3',
git: 'https://github.com/meteor/blaze.git'
});

Package.onUse(function (api) {
api.use('ecmascript@0.15.1');
api.use('htmljs@1.1.0');
api.use('htmljs@1.1.1');

api.export('BlazeTools');
api.mainModule('preamble.js');
Expand All @@ -18,7 +18,7 @@ Package.onTest(function (api) {
api.use('ecmascript');

api.use('blaze-tools');
api.use('html-tools@1.1.1');
api.use('html-tools@1.1.3');

api.addFiles([
'token_tests.js'
Expand Down
2 changes: 0 additions & 2 deletions packages/blaze/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,3 @@ Blaze._InOuterTemplateScope = function (templateView, contentFunc) {
return view;
};

// XXX COMPAT WITH 0.9.0
Blaze.InOuterTemplateScope = Blaze._InOuterTemplateScope;
24 changes: 20 additions & 4 deletions packages/blaze/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ var wrapHelper = function (f, templateFunc) {
};
};

function _lexicalKeepGoing(currentView) {
if (!currentView.parentView) {
return undefined;
}
if (!currentView.__startsNewLexicalScope) {
return currentView.parentView;
}
if (currentView.parentView.__childDoesntStartNewLexicalScope) {
return currentView.parentView;
}

// in the case of {{> Template.contentBlock data}} the contentBlock loses the lexical scope of it's parent, wheras {{> Template.contentBlock}} it does not
// this is because a #with sits between the include InOuterTemplateScope
if (currentView.parentView.name === "with" && currentView.parentView.parentView && currentView.parentView.parentView.__childDoesntStartNewLexicalScope) {
return currentView.parentView;
}
return undefined;
}

Blaze._lexicalBindingLookup = function (view, name) {
var currentView = view;
var blockHelpersStack = [];
Expand All @@ -99,10 +118,7 @@ Blaze._lexicalBindingLookup = function (view, name) {
return bindingReactiveVar.get();
};
}
} while (! (currentView.__startsNewLexicalScope &&
! (currentView.parentView &&
currentView.parentView.__childDoesntStartNewLexicalScope))
&& (currentView = currentView.parentView));
} while (currentView = _lexicalKeepGoing(currentView));

return null;
};
Expand Down
10 changes: 5 additions & 5 deletions packages/blaze/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'blaze',
summary: "Meteor Reactive Templating library",
version: '2.5.0',
version: '2.6.0',
git: 'https://github.com/meteor/blaze.git'
});

Expand All @@ -27,8 +27,8 @@ Package.onUse(function (api) {
'Handlebars'
]);

api.use('htmljs@1.1.0');
api.imply('htmljs@1.1.0');
api.use('htmljs@1.1.1');
api.imply('htmljs@1.1.1');

api.addFiles([
'preamble.js'
Expand Down Expand Up @@ -63,8 +63,8 @@ Package.onTest(function (api) {
api.use('tracker@1.1.0');

api.use('blaze');
api.use('blaze-tools@1.1.2'); // for BlazeTools.toJS
api.use('html-tools@1.1.0');
api.use('blaze-tools@1.1.3'); // for BlazeTools.toJS
api.use('html-tools@1.1.3');
api.use('templating');

api.addFiles('view_tests.js');
Expand Down
8 changes: 4 additions & 4 deletions packages/html-tools/package.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package.describe({
name: 'html-tools',
summary: "Standards-compliant HTML tools",
version: '1.1.2',
version: '1.1.3',
git: 'https://github.com/meteor/blaze.git'
});

Package.onUse(function (api) {
api.use('ecmascript@0.15.1');
api.use('htmljs@1.1.0');
api.imply('htmljs@1.1.0');
api.use('htmljs@1.1.1');
api.imply('htmljs@1.1.1');

api.export('HTMLTools');
api.mainModule('main.js');
Expand All @@ -19,7 +19,7 @@ Package.onTest(function (api) {
api.use('tinytest@1.1.0');

api.use('html-tools');
api.use('htmljs@1.1.0');
api.use('htmljs@1.1.1');
api.use('blaze-tools'); // for `toJS`

api.addFiles([
Expand Down
62 changes: 49 additions & 13 deletions packages/observe-sequence/observe_sequence.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
const isObject = function (value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
const has = function (obj, key) {
var keyParts = key.split('.');

return !!obj && (
keyParts.length > 1
? has(obj[key.split('.')[0]], keyParts.slice(1).join('.'))
: hasOwnProperty.call(obj, key)
);
};

const warn = function () {
if (ObserveSequence._suppressWarnings) {
ObserveSequence._suppressWarnings--;
Expand All @@ -15,7 +29,18 @@ const warn = function () {
// subclassed arrays: instanceof Array === true, _.isArray(arr) === false
// see specific tests
function isArray(arr) {
return arr instanceof Array || _.isArray(arr);
return arr instanceof Array || Array.isArray(arr);
}

// isIterable returns trues for objects implementing iterable protocol,
// except strings, as {{#each 'string'}} doesn't make much sense.
// Requires ES6+ and does not work in IE (but degrades gracefully).
// Does not support the `length` + index protocol also supported by Array.from
function isIterable (object) {
const iter = typeof Symbol != 'undefined' && Symbol.iterator;
return iter
&& object instanceof Object // note: returns false for strings
&& typeof object[iter] == 'function'; // implements iterable protocol
}

const idStringify = MongoID.idStringify;
Expand Down Expand Up @@ -94,7 +119,7 @@ ObserveSequence = {
if (activeObserveHandle) {
// If we were previously observing a cursor, replace lastSeqArray with
// more up-to-date information. Then stop the old observe.
lastSeqArray = _.map(lastSeq.fetch(), function (doc) {
lastSeqArray = lastSeq.fetch().map(function (doc) {
return {_id: doc._id, item: doc};
});
activeObserveHandle.stop();
Expand All @@ -110,6 +135,9 @@ ObserveSequence = {
seqChangedToCursor(lastSeqArray, seq, callbacks);
seqArray = result[0];
activeObserveHandle = result[1];
} else if (isIterable(seq)) {
const array = Array.from(seq);
seqArray = seqChangedToArray(lastSeqArray, array, callbacks);
} else {
throw badSequenceError(seq);
}
Expand Down Expand Up @@ -139,6 +167,8 @@ ObserveSequence = {
return seq;
} else if (isStoreCursor(seq)) {
return seq.fetch();
} else if (isIterable(seq)) {
return Array.from(seq);
} else {
throw badSequenceError(seq);
}
Expand Down Expand Up @@ -200,13 +230,17 @@ function sequenceGotValue(sequence) {

const badSequenceError = function (sequence) {
return new Error("{{#each}} currently only accepts " +
"arrays, cursors or falsey values." +
"arrays, cursors, iterables or falsey values." +
sequenceGotValue(sequence));
};

const isFunction = (func) => {
return typeof func === "function";
}

const isStoreCursor = function (cursor) {
return cursor && _.isObject(cursor) &&
_.isFunction(cursor.observe) && _.isFunction(cursor.fetch);
return cursor && isObject(cursor) &&
isFunction(cursor.observe) && isFunction(cursor.fetch);
};

// Calculates the differences between `lastSeqArray` and
Expand All @@ -221,11 +255,11 @@ const diffArray = function (lastSeqArray, seqArray, callbacks) {
var posCur = {};
var lengthCur = lastSeqArray.length;

_.each(seqArray, function (doc, i) {
seqArray.forEach(function (doc, i) {
newIdObjects.push({_id: doc._id});
posNew[idStringify(doc._id)] = i;
});
_.each(lastSeqArray, function (doc, i) {
lastSeqArray.forEach(function (doc, i) {
oldIdObjects.push({_id: doc._id});
posOld[idStringify(doc._id)] = i;
posCur[idStringify(doc._id)] = i;
Expand All @@ -242,7 +276,7 @@ const diffArray = function (lastSeqArray, seqArray, callbacks) {
if (before) {
// If not adding at the end, we need to update indexes.
// XXX this can still be improved greatly!
_.each(posCur, function (pos, id) {
Object.entries(posCur).forEach(function ([id, pos]) {
if (pos >= position)
posCur[id]++;
});
Expand Down Expand Up @@ -285,7 +319,7 @@ const diffArray = function (lastSeqArray, seqArray, callbacks) {
// 2. The element is moved back. Then the positions in between *and* the
// element that is currently standing on the moved element's future
// position are moved forward.
_.each(posCur, function (elCurPosition, id) {
Object.entries(posCur).forEach(function ([id, elCurPosition]) {
if (oldPosition < elCurPosition && elCurPosition < newPosition)
posCur[id]--;
else if (newPosition <= elCurPosition && elCurPosition < oldPosition)
Expand All @@ -305,7 +339,7 @@ const diffArray = function (lastSeqArray, seqArray, callbacks) {
removed: function (id) {
var prevPosition = posCur[idStringify(id)];

_.each(posCur, function (pos, id) {
Object.entries(posCur).forEach(function ([id, pos]) {
if (pos >= prevPosition)
posCur[id]--;
});
Expand All @@ -319,10 +353,12 @@ const diffArray = function (lastSeqArray, seqArray, callbacks) {
prevPosition);
}
});

Object.entries(posNew).forEach(function ([idString, pos]) {

_.each(posNew, function (pos, idString) {
var id = idParse(idString);
if (_.has(posOld, idString)) {

if (has(posOld, idString)) {
// specifically for primitive types, compare equality before
// firing the 'changedAt' callback. otherwise, always fire it
// because doing a deep EJSON comparison is not guaranteed to
Expand All @@ -345,7 +381,7 @@ seqChangedToEmpty = function (lastSeqArray, callbacks) {

seqChangedToArray = function (lastSeqArray, array, callbacks) {
var idsUsed = {};
var seqArray = _.map(array, function (item, index) {
var seqArray = array.map(function (item, index) {
var id;
if (typeof item === 'string') {
// ensure not empty, since other layers (eg DomRange) assume this as well
Expand Down
Loading

0 comments on commit a8dab83

Please sign in to comment.