Pasvaz/bindonce

Large number of $scopes created. normal?

noeticpenguin opened this issue · 3 comments

Good morning,

First, let me say, I love your work. I'm using it in a project and have run into an odd situation. it seems that every instance of bo-* creates a $scope. Is that normal? could i be doing it wrong? Is there a way to prevent that?

I'm using bindonce to cut down on watchers in a table I'm generating. 10rows X 17 columns, and the bindonce directive is on the Row , and the bo-Text calls are within spans. in fact here's an abreviated code snippet:

<tr ng-repeat="row in $data" ng-click="selectPanel(row)" bindonce="row" >
<td data-title="">
<i warnings-popover="{{ row.warning_message }}" 
popover-placement="right" bo-if="row.warning_message" class="glyphicon glyphicon-warning-sign" style="color: #8B0000; font-size: 14px;"/>
</td>
<apex:repeat value="{!fields}" var="col"> 
<td data-title="'{!col.Field_Label__c}'" sortable="'{!col.fieldPath__c}'" nowrap="nowrap" filter="{'{!col.fieldPath__c}':'{!col.Filter_Type__c}'} " >
<span 
bo-if="'{!col.Type__c}'.toUpperCase() == 'date'.toUpperCase()" 
bo-text="row['{!col.fieldPath__c}'] | date: 'MM/dd/yyyy'"
/>
<span 
bo-if="'{!col.Type__c}'.toUpperCase() == 'datetime'.toUpperCase()"
bo-text="row['{!col.fieldPath__c}'] | date: short"
/>

ng-if creates a scope and so does bo-if, luckily with bo-if you can avoid it using the attribute no-scope.
Btw you can avoid to setup bindonce with a value when you use it inside a repeater.

So, I feel a bit stupid, but I'm not sure how to actually use the no-scope bit? can you provide an example? We tried this:

<span 
bindonce="row.{!col.fieldPath__c}"
no-scope=""
bo-if="'{!col.Type__c}'.toUpperCase() == 'date'.toUpperCase()" 
bo-text="row['{!col.fieldPath__c}'] | date: 'MM/dd/yyyy'"
/>

but that didn't seem to stop a scope from being created. Unfortunately, our hosting environment (Salesforce) requires us to have xhtml4 compliant tags

no problem at all, I was a bit cryptic. Let's proceed with order:
First of all, bo-if works exactly like ng-if so by default it creates a scope, the experimental branch rebind (not ready for production) supports the possibility to avoid the scope creation, you just need to add no-scope attribute in the same element where you used bo-if as you did.
Pay attention, also ng-repeat create a new scope, so when you use ng-repeat and ng/bo-if in combination you can expect a lot of scopes around. In your first example, you creates 4 new scopes for each row so, for instance, if you have 100 records you'll creates 400 new scopes.