Skip to content

Commit 366b425

Browse files
Merge branch 'master' into djenkov/merge-release-master
2 parents 7236d32 + 27c1281 commit 366b425

21 files changed

Lines changed: 187 additions & 110 deletions

‎CodingConvention.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ let b = {"good": "code"
205205

206206
## Equality operator
207207

208-
Use the [strict comparison operators][comparisonoperators]. The triple equality operator helps to maintain data type integrity throughout code.
208+
Use the [strict comparison operators][comparisonoperators]. The triple equality operator helps to maintain data type integrity throughout the code.
209209

210210
*Right:*
211211

@@ -341,8 +341,8 @@ the last row of a big room can comfortably read. So don't count on them having
341341
perfect vision and limit yourself to 1/2 of your screen height per function (no screen rotation :).
342342

343343
## Return statements
344-
There are few important considerations here:
345-
+ To avoid deep nesting of if-statements, always return a functions value as early
344+
There are a few important considerations here:
345+
+ To avoid deep nesting of if-statements, always return a function's value as early
346346
as possible. In certain routines, once you know the answer, you want to return it to the calling routine immediately. If the routine is defined in such a way that it doesn't require any cleanup, not returning immediately means that you have to write more code.
347347
+ Minimize the number of returns in each routine. It's harder to understand a routine if, reading it at the bottom, you're unaware of the possibility that it *return*ed somewhere above.
348348

@@ -396,7 +396,7 @@ function getSomething(val) {
396396

397397
## Arrow Functions
398398

399-
Use arrow functions over anonymous function expressions. Typescript will take care for `this`.
399+
Use arrow functions over anonymous function expressions. Typescript will take care of `this`.
400400

401401
*Right:*
402402

@@ -423,7 +423,7 @@ req.on("end", function () {
423423

424424
Use the [JSDoc][JSDOC] convention for comments. When writing a comment always think how understandable will be for somebody who is new to this code. Even if it may look simple to you think how a guy that just joined will understand it. Always comment in the following cases:
425425
+ When there is some non-trivial logic.
426-
+ Some "external" knowledge is needed which is missing in the context - workaround for driver, module bug, special 'hack' because of a bug and so on;
426+
+ Some "external" knowledge is needed which is missing in the context - workaround for a driver, module bug, special 'hack' because of a bug and so on;
427427
+ When you are creating a new class
428428
+ Public methods - include all the arguments and if possible the types {String}, {Number}. Optional arguments should be marked too. Check the [@param tag][param]
429429

@@ -432,7 +432,7 @@ Use the [JSDoc][JSDOC] convention for comments. When writing a comment always th
432432

433433
## File/module structure
434434

435-
Typical module should have the following structure:
435+
A typical module should have the following structure:
436436

437437
1. required dependencies
438438
2. module-private declarations - variables, functions, classes, etc.
@@ -442,7 +442,7 @@ Typical module should have the following structure:
442442
For more information see [this file](https://github.com/telerik/xPlatCore/blob/master/JS/BCL/CreateNewModule.md)
443443

444444
## File naming
445-
Use lower case for file names. Use dash to separate different words.
445+
Use lower case for file names. Use a dash to separate different words.
446446

447447
*Right:*
448448
file-system
@@ -451,7 +451,7 @@ file-system
451451
FileSystem, fileSystem, file_system
452452

453453
## This, that, self
454-
When you **need** to keep reference to **this** use **that** as the name of the variable. Additionally, if you use the TypeScript lambda support, the compiler will take care of this automatically.
454+
When you **need** to keep a reference to **this** use **that** as the name of the variable. Additionally, if you use the TypeScript lambda support, the compiler will take care of this automatically.
455455

456456
*Right:*
457457
```TypeScript
@@ -470,7 +470,7 @@ doSomething(function(){
470470
```
471471

472472
## Private (hidden) variables and methods
473-
Although there is the **private** keyword in TypeScript, it is only a syntax sugar. There is no such notation in JavaScript and everything is available to the users. Hence, always use underscore (**_**) to prefix private variables and methods. There are also methods which have the **public** visibility but they are meant to be used within our code ONLY. Such methods should also be prefixed with underscore.
473+
Although there is the **private** keyword in TypeScript, it is only a syntax sugar. There is no such notation in JavaScript and everything is available to the users. Hence, always use underscore (**_**) to prefix private variables and methods. There are also methods which have the **public** visibility but they are meant to be used within our code ONLY. Such methods should also be prefixed with an underscore.
474474

475475
*Right:*
476476
```TypeScript

‎WritingUnitTests.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Writing Unit Tests for NativeScript Core Modules
22

33
Unit tests for NativeScript Modules are written and executed with a custom lightweight test-runner and assertion framework.
4-
The purpose of this document is to get you familiar with it, so that you can unit-test your contributions to the NativeScript framework.
4+
The purpose of this document is to get you familiar with it so that you can unit-test your contributions to the NativeScript framework.
55

66
# Run Unit Tests Project
77

@@ -19,7 +19,7 @@ tns run ios
1919
# Test Modules
2020

2121
All unit tests are organized into test modules(bundles).
22-
By default the test app will run all the tests from all registered test modules. This happens in [`runTests()`](/tests/app/app/mainPage.ts#L26-L28) method in the main page of the test-app. By modifying this method, you can configure the app to:
22+
By default, the test app will run all the tests from all registered test modules. This happens in [`runTests()`](/tests/app/app/mainPage.ts#L26-L28) method in the main page of the test-app. By modifying this method, you can configure the app to:
2323

2424
* **Execute only the tests from a specific test module**:
2525

@@ -50,8 +50,8 @@ The test modules are actually TypeScript modules which export unit tests and hoo
5050

5151
* All exported functions with a `test` prefix are unit-tests.
5252
* The `setUpModule()` hook is called once - before all the tests in the module.
53-
* The `setUp()` hook is called before each tests.
54-
* The `tearDown()` hook called after each tests.
53+
* The `setUp()` hook is called before each test.
54+
* The `tearDown()` hook called after each test.
5555
* The `tearDownModule()` hook is called once - after all the tests in the module.
5656

5757
# Asserting
@@ -85,4 +85,4 @@ export function test_getJSON(done) {
8585

8686
# Misc
8787

88-
When looking into the code of the existing tests, you might encounter strange comments looking like this `// >> animation-chaining`. These are markers for code snippets generated in the docs documetation. They are not related to testing so you don't need to add any of those in your tests.
88+
When looking into the code of the existing tests, you might encounter strange comments looking like this `// >> animation-chaining`. These are markers for code snippets generated in the docs documentation. They are not related to testing so you don't need to add any of those in your tests.
200 KB
Loading

‎tests/app/ui/styling/style-tests.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,23 @@ export function test_CSS_isAppliedOnPage_From_addCssFile() {
674674
});
675675
}
676676

677+
export function test_CSS_isAppliedOnPage_From_changeCssFile() {
678+
const testButton = new buttonModule.Button();
679+
testButton.text = "Test";
680+
681+
const testCss = "button { color: blue; }";
682+
683+
const testFunc = function (views: Array<viewModule.View>) {
684+
helper.assertViewColor(testButton, "#0000FF");
685+
const page: pageModule.Page = <pageModule.Page>views[1];
686+
page.changeCssFile("~/ui/styling/test.css");
687+
helper.assertViewBackgroundColor(page, "#FF0000");
688+
TKUnit.assert(testButton.style.color === undefined, "Color should not have a value");
689+
}
690+
691+
helper.buildUIAndRunTest(testButton, testFunc, { pageCss: testCss });
692+
}
693+
677694
const invalidCSS = ".invalid { " +
678695
"color: invalidValue; " +
679696
"background-color: invalidValue; " +

‎tns-core-modules/application/application-common.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
iOSApplication,
4040
LoadAppCSSEventData,
4141
UnhandledErrorEventData,
42-
DiscardedErrorEventData
42+
DiscardedErrorEventData,
4343
} from "./application";
4444

4545
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
@@ -82,19 +82,23 @@ export function setApplication(instance: iOSApplication | AndroidApplication): v
8282
export function livesync(rootView: View, context?: ModuleContext) {
8383
events.notify(<EventData>{ eventName: "livesync", object: app });
8484
const liveSyncCore = global.__onLiveSyncCore;
85-
let reapplyAppCss = false;
85+
let reapplyAppStyles = false;
86+
let reapplyLocalStyles = false;
8687

87-
if (context) {
88-
const fullFileName = getCssFileName();
89-
const fileName = fullFileName.substring(0, fullFileName.lastIndexOf(".") + 1);
88+
if (context && context.path) {
9089
const extensions = ["css", "scss"];
91-
reapplyAppCss = extensions.some(ext => context.path === fileName.concat(ext));
90+
const appStylesFullFileName = getCssFileName();
91+
const appStylesFileName = appStylesFullFileName.substring(0, appStylesFullFileName.lastIndexOf(".") + 1);
92+
reapplyAppStyles = extensions.some(ext => context.path === appStylesFileName.concat(ext));
93+
if (!reapplyAppStyles) {
94+
reapplyLocalStyles = extensions.some(ext => context.path.endsWith(ext));
95+
}
9296
}
9397

94-
if (reapplyAppCss && rootView) {
98+
if (reapplyAppStyles && rootView) {
9599
rootView._onCssStateChange();
96100
} else if (liveSyncCore) {
97-
liveSyncCore();
101+
reapplyLocalStyles ? liveSyncCore(context) : liveSyncCore();
98102
}
99103
}
100104

‎tns-core-modules/application/application.d.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* @module "application"
44
*/ /** */
55

6-
///<reference path="../tns-core-modules.d.ts" /> Include global typings
6+
/// <reference path="../nativescript-error.d.ts" />
7+
/// <reference path="../tns-core-modules.d.ts" />
8+
79
import { NavigationEntry, View, Observable, EventData } from "../ui/frame";
810

911
/**
@@ -607,4 +609,4 @@ export function hasLaunched(): boolean;
607609

608610
export interface LoadAppCSSEventData extends EventData {
609611
cssFile: string;
610-
}
612+
}

‎tns-core-modules/application/application.ios.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ class IOSApplication implements IOSApplicationDefinition {
225225
}
226226
}
227227

228-
public _onLivesync(): void {
228+
public _onLivesync(context?: ModuleContext): void {
229229
// If view can't handle livesync set window controller.
230-
if (this._rootView && !this._rootView._onLivesync()) {
230+
if (this._rootView && !this._rootView._onLivesync(context)) {
231231
this.setWindowContent();
232232
}
233233
}
@@ -264,8 +264,8 @@ exports.ios = iosApp;
264264
setApplication(iosApp);
265265

266266
// attach on global, so it can be overwritten in NativeScript Angular
267-
(<any>global).__onLiveSyncCore = function () {
268-
iosApp._onLivesync();
267+
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) {
268+
iosApp._onLivesync(context);
269269
}
270270

271271
let mainEntry: NavigationEntry;

‎tns-core-modules/debugger/webinspector-css.ios.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class CSSDomainDebugger implements inspectorCommandTypes.CSSDomain.CSSDom
1818
this.commands = {};
1919

2020
attachCSSInspectorCommandCallbacks(this.commands);
21+
22+
// By default start enabled because we can miss the "enable" event when
23+
// running with `--debug-brk` -- the frontend will send it before we've been created
24+
this.enable();
2125
}
2226

2327
get enabled(): boolean {

‎tns-core-modules/debugger/webinspector-dom.ios.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export class DOMDomainDebugger implements inspectorCommandTypes.DOMDomain.DOMDom
2020

2121
attachDOMInspectorEventCallbacks(this.events);
2222
attachDOMInspectorCommandCallbacks(this.commands);
23+
24+
// By default start enabled because we can miss the "enable event when
25+
// running with `--debug-brk` -- the frontend will send it before we've been created
26+
this.enable();
2327
}
2428

2529
get enabled(): boolean {

‎tns-core-modules/debugger/webinspector-network.ios.ts‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class Request {
6464
this._resourceType = "Other";
6565
return;
6666
}
67-
67+
6868
this._mimeType = value;
6969

7070
var resourceType = "Other";
@@ -112,19 +112,19 @@ export class Request {
112112
this._resourceType = value;
113113
}
114114
}
115-
115+
116116
public responseReceived(response: inspectorCommandTypes.NetworkDomain.Response): void {
117117
if (this._networkDomainDebugger.enabled) {
118118
this._networkDomainDebugger.events.responseReceived(this.requestID, frameId, loaderId, __inspectorTimestamp(), <any>this.resourceType, response);
119119
}
120120
}
121-
121+
122122
public loadingFinished(): void {
123123
if (this._networkDomainDebugger.enabled) {
124124
this._networkDomainDebugger.events.loadingFinished(this.requestID, __inspectorTimestamp());
125125
}
126126
}
127-
127+
128128
public requestWillBeSent(request: inspectorCommandTypes.NetworkDomain.Request): void {
129129
if (this._networkDomainDebugger.enabled) {
130130
this._networkDomainDebugger.events.requestWillBeSent(this.requestID, frameId, loaderId, request.url, request, __inspectorTimestamp(), { type: "Script" });
@@ -136,9 +136,13 @@ export class Request {
136136
export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomain.NetworkDomainDispatcher {
137137
private _enabled: boolean;
138138
public events: inspectorCommandTypes.NetworkDomain.NetworkFrontend;
139-
139+
140140
constructor() {
141141
this.events = new inspectorCommands.NetworkDomain.NetworkFrontend();
142+
143+
// By default start enabled because we can miss the "enable" event when
144+
// running with `--debug-brk` -- the frontend will send it before we've been created
145+
this.enable();
142146
}
143147

144148
get enabled(): boolean {
@@ -156,7 +160,7 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
156160
}
157161
this._enabled = true;
158162
}
159-
163+
160164
/**
161165
* Disables network tracking, prevents network events from being sent to the client.
162166
*/
@@ -166,14 +170,14 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
166170
}
167171
this._enabled = false;
168172
}
169-
173+
170174
/**
171175
* Specifies whether to always send extra HTTP headers with the requests from this page.
172176
*/
173177
setExtraHTTPHeaders(params: inspectorCommandTypes.NetworkDomain.SetExtraHTTPHeadersMethodArguments): void {
174178
//
175179
}
176-
180+
177181
/**
178182
* Returns content served for the given request.
179183
*/
@@ -187,9 +191,9 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
187191
body: body,
188192
base64Encoded: !resource_data.hasTextContent
189193
};
190-
}
194+
}
191195
}
192-
196+
193197
/**
194198
* Tells whether clearing browser cache is supported.
195199
*/
@@ -198,14 +202,14 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
198202
result: false
199203
};
200204
}
201-
205+
202206
/**
203207
* Clears browser cache.
204208
*/
205209
clearBrowserCache(): void {
206210
//
207211
}
208-
212+
209213
/**
210214
* Tells whether clearing browser cookies is supported.
211215
*/
@@ -214,21 +218,21 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
214218
result: false
215219
};
216220
}
217-
221+
218222
/**
219223
* Clears browser cookies.
220224
*/
221225
clearBrowserCookies(): void {
222226
//
223227
}
224-
228+
225229
/**
226230
* Toggles ignoring cache for each request. If <code>true</code>, cache will not be used.
227231
*/
228232
setCacheDisabled(params: inspectorCommandTypes.NetworkDomain.SetCacheDisabledMethodArguments): void {
229233
//
230234
}
231-
235+
232236
/**
233237
* Loads a resource in the context of a frame on the inspected page without cross origin checks.
234238
*/
@@ -245,7 +249,7 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai
245249
status: 200
246250
}
247251
}
248-
252+
249253
public static idSequence: number = 0;
250254
create(): Request {
251255
let id = (++NetworkDomainDebugger.idSequence).toString();
@@ -264,4 +268,4 @@ export class RuntimeDomainDebugger {
264268
compileScript(): { scriptId?: string, exceptionDetails?: Object } {
265269
return {};
266270
}
267-
}
271+
}

0 commit comments

Comments
 (0)