<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lajos Gallay on Medium]]></title>
        <description><![CDATA[Stories by Lajos Gallay on Medium]]></description>
        <link>https://medium.com/@gallayl?source=rss-b8ec9e374f72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_eXf4NoBRYaDOG8X.</url>
            <title>Stories by Lajos Gallay on Medium</title>
            <link>https://medium.com/@gallayl?source=rss-b8ec9e374f72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:26:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gallayl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scoped packages]]></title>
            <link>https://medium.com/sensenet/scoped-packages-6e066b064ba4?source=rss-b8ec9e374f72------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e066b064ba4</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[sensenet]]></category>
            <category><![CDATA[packaging]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Lajos Gallay]]></dc:creator>
            <pubDate>Wed, 21 Feb 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-02-21T13:43:22.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yvtzNKvUaWIwdSBO.jpg" /></figure><p>We’ve started 2018 with a huge package refactor: we have divided our base <em>sn-client-js</em> package into several smaller ones and published them within a <em>@sensenet</em> scope. We’ve refactored a lot of code to simplify our API, improve working with immutable objects and also did a strict review on our dependencies. I will summarize the reasons, the improvements and what has been changed.</p><h3>Why?</h3><p>Long story short: our all-in-one <em>sn-client-js</em> has started to grow too fast. The development started to getting slower and harder. The package contained some well-separable parts (like querying, default content types or repository events) that could be easily extracted into separate packages. It had some parts (like the Repository and Content API) that we had to rethink and some parts (like internal modules or namespaces) that are no longer recommended to use.</p><h3>Immutable objects</h3><p>Redux — as many other libraries nowadays — uses <em>shallow equality checking</em> for change detection and therefore it needs to work with <a href="https://redux.js.org/docs/faq/ImmutableData.html">immutable data</a>. Our Content and Repository API-s were not fully prepared to work with immutable objects: our rich-domain-inspired Content API had its own change detection mechanism. We had to rethink the concepts of the client side repository and content API implementation in terms of immutability.</p><h3>Internal modules and namespaces</h3><p>We’ve packed a lot of things in <strong>sn-client-js</strong>: default content type and schema definitions, logics for querying on OData, authentication logics, etc… They were organized into <em>internal modules and namespaces</em>. This approach is less and less recommended, nowadays namespacing is even considered as <a href="https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html">needless</a> by TypeScript. There were some modules (like the default Content Types) that were worth extracting into separate packages.</p><h3>The size of sn-client-js@³.0.3 in numbers</h3><p>Based on the generated Typedoc documentation, we have 205 classes, 13 enums, 7 interfaces in the 23 internal modules.</p><p>If you install sn-client-js into your NPM project, it will contain about 890 files and will take about 20MB of space.</p><p>If you clone and install the latest sn-client-js, you will have <strong>275</strong> folders in your <em>node_modules</em> folder and the whole package size is approx 160 MB.</p><p>The package contains about <strong>~458</strong> unit tests that isn’t a problem itself: it takes less than roughly a second to complete. But with the full build process it takes <strong>~20</strong> seconds.</p><h3>The goals</h3><p>We wanted to divide our overgrown client side packages — especially our <em>base</em> package, <em>sn-client-js</em> — into smaller, lightweight ones. NPM offers <a href="https://docs.npmjs.com/misc/scope">package scoping</a>, so we’ve decided to publish the new packages within a <strong>@sensenet</strong> scope.</p><p>We wanted some features — like repository events, mapping controls to schemas or even JWT authentication itself — to be fully optional. We wanted to review if we can switch to some native APIs from external NPM libraries — for example in terms of RxJs and native promises with fetch API. We wanted to catch up with the industry standards in terms of immutability and standardize our linting settings.</p><p>We also wanted to take a look on our build, test and publish processes and — last but not least — the content of our NPM packages.</p><h3>The new packages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sr2wN-1Rk7uUMSY_.png" /></figure><h3><a href="https://www.npmjs.com/package/@sensenet/client-utils">client-utils</a></h3><p>This package contains some generic utilities — like helpers for disposable objects, a retrier, a method tracer and a simple value observer implementation — and <em>without any sensenet ECM dependencies</em>, so it can be used in any project.</p><h3><a href="https://www.npmjs.com/package/@sensenet/query">query</a></h3><p>If you want to create typesafe content queries you can do that with this package. It has a fluent API to create a query from a generic type argument.</p><h3><a href="https://www.npmjs.com/package/@sensenet/default-content-types">default-content-types</a></h3><p>We store the default generated content types, schema definitions, enums, etc… in this package. This package (unlike the others) doesn’t contain any unit tests as it doesn’t contain application logic — it can be used as a content type / schema library.</p><h3><a href="https://www.npmjs.com/package/@sensenet/client-core">client-core</a></h3><p>The <em>core</em> logic sits in this package, if you want to interact with sensenet ECM its a good starting point to install it. It contains the refactored <em>Repository</em> object itself, you can load / modify / delete content and execute custom action from there. It also contains some predefined security and versioning related actions, response models, interfaces and abstracts.</p><h3><a href="https://www.npmjs.com/package/@sensenet/authentication-jwt">authentication-jwt</a></h3><p>If you install the <a href="https://www.npmjs.com/package/@sensenet/client-core">@sensenet/client-core</a> package, it bypasses authentication by default. That means if you need JWT authentication, you have to install this package as well and configure it on your <em>repository</em> instance.</p><h3><a href="https://www.npmjs.com/package/@sensenet/authentication-google">authentication-google</a></h3><p>It contains the Google Oauth authentication implementation. This package depends on JWT, but it’s fully optional.</p><h3><a href="https://www.npmjs.com/package/@sensenet/control-mapper">control-mapper</a></h3><p>It contains an utility that helps to map third party controls to generated sensenet schemas. It’s optional, but used by our control packages.</p><h3><a href="https://www.npmjs.com/package/@sensenet/repository-events">repository-events</a></h3><p>If you want to listen to specific repository events — like a content change — you can use this package. This is also optional, but we use it in <a href="https://www.npmjs.com/package/@sensenet/controls-aurelia">@sensenet/controls-aurelia</a></p><h3><a href="https://www.npmjs.com/package/@sensenet/controls-aurelia">@sensenet/controls-aurelia</a></h3><p>Our Aurelia control package has been refactored. The main change here is that it uses packages from the @sensenet scope as dependencies.</p><h3>Concept changes</h3><h3>Removed content API, cleaned up Repository API</h3><p>The main change is that the Content API itself has been removed. Most of its responsibilities has been taken by the Repository — in the most cases this means that e.g. myContent.checkout(); has been moved to repository.versioning.checkOut(myContent.Id);.</p><p>Another breaking chage is that in the future content creation and updates will be possible only on <em>repository instances</em> via the exposed <strong>post/patch/put</strong> methods. That means that myContent.save() will be changed to repository.patch({idOrPath: myContent.Id, content: myContent}).</p><h3>Promises, fetch and disposables</h3><p>In sn-client-js we used RxJs observables for asynchronous operations. We’ve removed the whole RxJs library from our dependencies and switched to native ES6 promises and to the native <strong>fetch</strong> method. That means that you can use now the <a href="https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9">async / await</a> syntax with sensenet calls.</p><p>There are a few observables like the current user, the login state or the repository events, they use our own simplified <a href="https://github.com/SenseNet/sn-client-utils">observable</a> implementation. The difference is that these observables are also <em>disposables</em> so if you want to stop receiving updates, you have to dispose() them.</p><h3>Less transformation</h3><p>We’ve reviewed and removed a lots of transformations in terms of odata requests, that means you will have access to the original json object and you can transform it afterwards.</p><h3>Package optimizations</h3><p>One of the main goals was that our new packages should be small and lightweight. We’ve started with a strict dependency review that included the indirect dependencies as well. We’ve started to change our scripts to NPM scripts from Gulp tasks earlier and now we didn’t have any dependency on Gulp. As I’ve mentioned earlier we’ve switched to native promises and we could remove our dependency on RxJs that is a huge package itself.</p><p>We’ve used another package in our unit tests called <em>mocha-typescript</em> that enables unit test running with a nice decorator syntax — but it had <a href="http://npm.anvaka.com/#/view/2d/mocha-typescript">~59</a> indirect dependencies, so we’ve also changed our unit tests to the plain mocha syntax.</p><p>Now most of our packages doesn’t even have any external dependency that you <em>have to install</em>.</p><p>We’ve continued with reviewing our processes: We use <a href="http://typedoc.org/">Typedoc</a> for API Docs generation — this is a great tool however also adds about <a href="http://npm.anvaka.com/#/view/2d/typedoc">60</a> package as indirect dependency. We also use commitizen for GIT commit message formatting, but it means about <a href="http://npm.anvaka.com/#/view/2d/commitizen">134</a> indirect dependencies. These two tools play an important role in our internal processes but not during development — therefore we’ve decided to remove them even from our <em>devDependencies</em> and install them as global NPM packages.</p><p>We’ve started to optimize our NPM package sizes next. We’ve removed the coverage reports — you can still check them on <a href="https://codecov.io/">Codecov</a> — and the generated API Docs. They will be published into our <a href="https://community.sensenet.com/docs/">community site</a> soon.</p><p>As the last step we’ve separated our <strong>build</strong> and <strong>build:test</strong> processes — the test artifacts will be compiled into a <em>temporary folder</em> and will be excluded from the NPM package and the <strong>dist</strong> folder will contain only that artifacts that the package uses.</p><p>The results: If you are using the scoped packages in your NPM project, the current version — with JWT, Google Oauth, the Repository events and the control mapper will — take <strong>~2MB</strong> of space (sn-client-js took nearly 20MB).</p><p>Most of our scoped packages <strong>won’t install any third party package</strong>. The only exceptions will be that packages that will <em>rely</em> on a specific framework or library, like the <em>Aurelia-controls</em> or the Redux package.</p><p>If you are developing a scoped package and you install the <em>dev dependencies</em> as well it will take <em>less than a half of the size of sn-client-js</em> (~66 MB vs ~149 MB in size, ~7000 files vs ~20 000 files).</p><p>The full build and unit testing time has also been improved — from about ~20sec to ~5sec.</p><h3>Changes</h3><p>As I mentioned earlier there are no internal namespaces in the scoped packages — therefore you can <em>import</em> exactly just the classes / methods that you will need. I’ve collected a some common examples.</p><h3>Creating a Repository</h3><p>You can start installing the <em>core</em> package with the npm install @sensenet/client-core command and creating a repository:</p><pre>import { Repository } from &#39;@sensenet/client-core&#39;;</pre><pre>const repo = new Repository({<br>     repositoryUrl: &quot;https://my-sensenet7-instance.com&quot;,<br>});</pre><h3>Configuring JWT and Google OAuth</h3><p>As JWT is an optional feature, you have to install the corresponding package with the npm install @sensenet/authentication-jwt and you have to configure it after repository creation in the following way:</p><pre>import { JwtService } from &quot;@sensenet/authentication-jwt&quot;;</pre><pre>const jwtService = new JwtService(repo);</pre><p>Once you have JWT, you can set up Google Oauth easily after installing the package <strong>@sensenet/authentication-jwt</strong>:</p><pre>import { addGoogleAuth, GoogleOauthProvider } from &#39;@sensenet/authentication-google&#39;;</pre><pre>const googleAuthProvider: GoogleOauthProvider = addGoogleAuth(jwtService, { clientId: &#39;my-google-client-id&#39;, })</pre><h3>Loading a content</h3><p>There are some major changes when it comes to content loading. The first one is that the packages use <em>promises</em>, as mentioned above, so from now on the operations can be <em>awaited</em>.</p><p>The second one is that we’ve eliminated many unneccessary data transformations, so you can work with the plain serialized data object from the response itself. This also means that you cannot use “instanceof”-type checks on these object, you can use the “Type” property at runtime and <em>generics</em> in TypeScript during development.</p><p>There are two methods — load and loadCollection — that can be used for loading single contents / one-to-one references and collections / one-to-many references.</p><pre>const portalUsers = await repo.loadCollection&lt;User&gt;({<br>   path: &quot;/Root/IMS/BuiltIn/Portal&quot;,<br>   oDataOptions: { /** additional options */ }, <br>});</pre><pre>console.log(&quot;Count: &quot;, portalUsers.d.__count);<br>console.log(&quot;Users: &quot;, portalUsers.d.results);</pre><p>There are also some breaking changes with the content creating / updating API: The POST/PUT/PATCH methods are now available directly on repository instances. You can also use TypeScript generics.</p><pre>const response = await repository.patch&lt;User&gt;({<br>   idOrPath: &quot;Root/Example/My_Content&quot;,<br>   content: { LoginName: &quot;myNewLoginName&quot;, },<br>   oDataOptions: { /** additional options */ },<br>});</pre><h3>Other actions</h3><p>The bacth actions (copy, move and delete) are also available on repository instances and you can also find the <em>security</em> and <em>versioning</em> under the corresponding namespace.</p><p>If you have custom OData actions implemented, you can use the executeAction method as shown in the example above - or wrap them with strongly typed method calls like we did for the Security and Versioning related actions:</p><pre>const response: Promise&lt;TReturns&gt; =<br>   repo.executeAction&lt;TPostBody, TReturns&gt;({<br>      name: &quot;MyCustomAction&quot;,<br>      idOrPath: &quot;Root/Example/Content&quot;,<br>      method: &quot;POST&quot;, // or GET body: {<br>         { myCustomPostData: myCustomValue } as TPostBody,<br>      },<br>   })</pre><h3>Further goals</h3><p>Although the scoped packages has been published, we have still some tasks remaining: We have to publish the API documentation to the community site and update our tutorials.</p><p>We’ve already started to update our Redux package, review its dependencies and improve the async operations — it will be also a scoped package. After that we can update our React controls package as well.</p><p>We also plan to update our command line tool to allow developers fetching their content types from CTDs but before we do that we want to improve the <em>client-side schema loading</em>.</p><p>We hope that sensenet ECM development will be simpler and more fun than ever with the new packages. If you have any questions or thoughts don’t hesitate to share with us :)</p><p>Have feedback on this post? Let <a href="https://twitter.com/sensenet">@sensenet</a> know on Twitter.</p><p>Need help or found a bug? <a href="https://community.sensenet.com/contact">Contact us</a>.</p><p><em>Originally published at </em><a href="https://community.sensenet.com/blog/2018/02/21/scoped-packages"><em>community.sensenet.com</em></a><em> on February 21, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e066b064ba4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sensenet/scoped-packages-6e066b064ba4">Scoped packages</a> was originally published in <a href="https://medium.com/sensenet">sensenet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with sensenet ECM using Aurelia Framework]]></title>
            <link>https://medium.com/sensenet/getting-started-with-sensenet-ecm-using-aurelia-framework-621f8717d6db?source=rss-b8ec9e374f72------2</link>
            <guid isPermaLink="false">https://medium.com/p/621f8717d6db</guid>
            <category><![CDATA[aurelia]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[sensenet-ecm]]></category>
            <dc:creator><![CDATA[Lajos Gallay]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-01-11T10:05:12.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L_7OS_Cxdpqgzmd5.jpg" /></figure><p>There was a lot of development in the frontent frameworks ecosystem over the last couple of years — and you can use a wide range of them with the latest version of <em>sensenet ECM</em>. The following step by step tutorial will guide you how to put it all together — this time with <a href="http://aurelia.io/">Aurelia</a> and <a href="https://www.typescriptlang.org/">Typescript</a>.</p><h3>Prerequisites</h3><p>First of all, you’ll need <a href="https://community.sensenet.com/docs/install-sn-from-nuget/">sensenet Services</a> installed and configured <a href="https://community.sensenet.com/docs/web-token-authentication/">JWT Authentication</a>. <a href="https://community.sensenet.com/docs/install-webpages-from-nuget/">Webpages installation</a> is not a requirement but also recommended.</p><p>You’ll also have to deal with the <a href="https://community.sensenet.com/docs/cors/">CORS</a> settings. You have to allow CORS for <strong>localhost</strong> origin. Add the following setting to your <strong>Portal.settings</strong> file that can be found in <strong>/Root/System/Settings/Portal.settings</strong> (You can use the <em>Content Explorer</em> if you have WebPages installed, or just re-import the modified file) :</p><pre>... &quot;AllowedOriginDomains&quot;: [ &quot;localhost&quot; ] ...</pre><h3>Creating the app with aurelia-cli</h3><p>Aurelia has a great CLI tool that allows us to create custom elements, value converters or even an entire preconfigured Aurelia project with simple commands. You can install it globally from NPM:</p><pre>npm install -g aurelia-cli</pre><p>You can set up and create a new Aurelia application with the following CLI command:</p><p>Create your project choosing the <strong>custom settings</strong>, my setup looks like the following:</p><ul><li>Name: <strong>my-sensenet-app</strong></li><li>Platform: <strong>Web</strong></li><li>Bundler: <strong>Webpack</strong></li><li>Loader: <strong>None</strong></li><li>Transpiler: <strong>TypeScript</strong></li><li>Markup Processor: <strong>None</strong></li><li>CSS Processor: <strong>Sass</strong></li><li>Unit Test Runner: <strong>Jest</strong></li><li>Integration Test Runner: <strong>Protractor</strong></li><li>Editor: <strong>Visual Studio Code</strong></li></ul><p>You can change the CSS preprocessor or test runners, we won’t use them for now.</p><p>Once the setup is done, you can install the dependencies (or do it later with the npm install command).</p><p>You can run your Aurelia app with the following command:</p><pre>cd my-sensenet-app au run</pre><p>After a quick build process you will see the development server’s URL on the console (it is <a href="http://localhost:8080/">http://localhost:8080</a> by default). Open it in your browser and check the default <em>Hello World!</em> message.</p><h3>Getting started with sn-client-js</h3><h3>Install</h3><p>To work with sensenet ECM, the first thing you have to do is to install the <a href="https://www.npmjs.com/package/sn-client-js">sn-client-js</a> package with the following command:</p><pre>npm install sn-client-js</pre><h3>Configuring dependency injection</h3><p>In this example we will use the <em>Repository</em> from sn-client-js as a main entry point to interact with sensenet ECM. In order to inject a preconfigured <em>repository</em> as a singleton, we have to configure Aurelia’s main <em>DI container</em>.</p><p>Open <strong>./src/main.ts</strong> and add the following import:</p><pre>import { Repository } from &#39;sn-client-js&#39;;</pre><p>and before the aurelia.start()… statement:</p><pre>aurelia.container.registerSingleton(Repository.BaseRepository, () =&gt; new Repository.SnRepository(<br>    {<br>      RepositoryUrl: &#39;<a href="https://sensenet7-local/">https://sensenet7-local</a>&#39;, // Change this URL to your sensenet 7 Repository<br>    })<br>  );</pre><h3>Login and Logout</h3><h3>Creating a custom element with CLI</h3><p>Now we will create a <em>custom element</em> called <strong>sn-login</strong>. This will have similar functionality as the <em>LoginPortlet</em>, it will display a simple login form for unauthenticated users and a welcome message with a Logout button if you are logged in. We can create the element with the following CLI command:</p><pre>au generate element sn-login</pre><p>The CLI will create a view-model and a HTML template in <em>./src/resources/</em>. To register our element as a <em>global resource</em> open <strong>./src/resources/index.ts</strong> and update:</p><pre>import {FrameworkConfiguration, PLATFORM} from &#39;aurelia-framework&#39;;<br><br>export function configure(config: FrameworkConfiguration) {<br>  config.globalResources([<br>    PLATFORM.moduleName(&#39;./elements/sn-login&#39;)<br>  ]);<br>}</pre><p>To display our new element we have to edit the main application template that can be found in <strong>./src/app.html</strong>. Let’s remove the static <em>Hello World!</em> header and add our new sn-login <em>custom element</em>:</p><pre>&lt;template&gt;<br>  &lt;sn-login&gt;&lt;/sn-login&gt;<br>&lt;/template&gt;</pre><p>To edit <em>sn-login</em> element’s view model, we have to open the generated <strong>./src/resources/elements/sn-login.ts</strong> file. We can remove the example bindable <em>value</em> and its <em>valueChanged</em> method.</p><p>First we will need an SnRepository instance. We will inject it using Aurelia’s <em>autoInject</em> decorator.</p><pre>import { bindable, autoinject } from &#39;aurelia-framework&#39;;<br>import { Repository, Content, ContentTypes, Authentication } from &#39;sn-client-js&#39;;<br>import { Subscription } from &#39;rxjs&#39;;<br><br>@autoinject<br>export class SnLogin {<br>  constructor(private repository: Repository.BaseRepository) {  }<br>}</pre><p>From now on, we can use the <em>repository</em> in our custom element. We will use two <a href="http://reactivex.io/documentation/observable.html">RxJs observables</a> in this component, one to track the login state and another one to track the current user.</p><p>We will create two <em>subscriptions</em> and store their current value in two <em>bindable properties</em>. We will subscribe in <em>attached</em> component event and unsubscribe in <em>detached</em>.</p><p>You can add the following code to your view-model:</p><pre>@bindable <br>  currentUser: Content&lt;ContentTypes.User&gt;<br><br>  @bindable<br>  loginState: Authentication.LoginState<br><br>  subscriptions: Subscription[] = [];<br><br>  attached(){<br>    this.subscriptions.push(<br>      this.repository.Authentication.State.subscribe(state=&gt;{<br>        this.loginState = state;<br>      }),<br>      this.repository.GetCurrentUser().subscribe(user =&gt; {<br>        this.currentUser = user;<br>      })<br>    )<br>  }<br>  detached(){<br>    this.subscriptions.forEach(s =&gt; s.unsubscribe());<br>  }</pre><p>Once the coding is done, we will modify the <em>template</em> that can be found in <strong>./src/resources/elements/sn-login.html</strong>. First, we can display the login state and the current user’s DisplayName.</p><pre>&lt;template&gt;<br>  &lt;p&gt;<br>    Hello &lt;strong&gt;${currentUser.DisplayName}&lt;/strong&gt; &lt;br /&gt;<br>    The login state is &lt;strong&gt;${loginState}&lt;/strong&gt;<br>  &lt;/p&gt;<br>&lt;/template&gt;</pre><p>If you start the project now with au start and open the page, you will see a ‘Hello <strong>Visitor</strong>!’ message and the login state will be <strong>Unauthenticated</strong>.</p><h3>Creating a basic login and logout form</h3><p>Now we know the user and the login state, we can improve the element template a bit. We will display the followings:</p><ul><li>If the <em>loginState</em> is <strong>Unauthenticated</strong> the user will get a login form with username and password fields</li><li>If the state is <strong>Authenticated</strong>, a welcome message and a Logout button</li><li>If the login state is <strong>Pending</strong>, well… a message for now and you can replace it with your favourite loader later :)</li></ul><p>Now the template will look like this:</p><pre>&lt;template&gt;<br>  &lt;form if.bind=&quot;loginState === &#39;Unauthenticated&#39;&quot; submit.delegate=&quot;login()&quot;&gt;<br>    &lt;input type=&#39;text&#39; required name=&quot;username&quot; value.bind=&#39;loginUserName&#39; /&gt;<br>    &lt;input type=&quot;password&quot; required name=&quot;password&quot; value.bind=&#39;loginPassword&#39; /&gt;<br>    &lt;input type=&#39;submit&#39; /&gt;<br>  &lt;/form&gt;<br>  &lt;p if.bind=&quot;loginState === &#39;Authenticated&#39;&quot;&gt;<br>    Hello &lt;strong&gt;${currentUser.DisplayName}!&lt;/strong&gt; &lt;br /&gt;<br>    &lt;button click.delegate=&quot;logout()&quot;&gt;Log out&lt;/button&gt;<br>  &lt;/p&gt;<br>  &lt;p if.bind=&quot;loginState === &#39;Pending&#39;&quot;&gt;<br>    Login in progress...<br>  &lt;/p&gt;<br>  The login state is &lt;strong&gt;${loginState}&lt;/strong&gt;  <br>&lt;/template&gt;</pre><p>We will add two properties into the view-model called <em>loginUserName</em> and <em>loginPassword</em>, the form values will be bound to these properties.</p><pre>@bindable<br>loginUserName: string;<br>@bindable<br>loginPassword: string;</pre><p>And we have to implement the actions for <em>login()</em> and <em>logout()</em> — they will simply call the corresponding endpoints on the Repository.</p><pre>login(){<br>  this.repository.Authentication.Login(this.loginUserName, this.loginPassword);<br>  this.loginUserName = this.loginPassword = &quot;&quot;;<br>}<br><br>logout(){<br>  this.repository.Authentication.Logout();<br>}</pre><p>Once we’ve got it up and running we will be able to log in and out and display the user name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/0*InrV_QF0Si5ractU.gif" /></figure><h3>Content list component</h3><h3>Creating and setting up the component</h3><p>In the next example we will create another custom element that <em>list</em> content from the repository. To do that, we will create another custom element with the au generate element content-list command and add it as a global resource in <strong>./src/resources/index.ts</strong> just like the <em>sn-login</em> element.</p><p>We have to add it into our main <em>app</em> component, it will be available if the user is <em>authenticated</em>. Open <strong>./src/app.html</strong> and add the new component:</p><pre>&lt;template&gt;<br>  &lt;sn-login&gt;&lt;/sn-login&gt;<br>  &lt;content-list if.bind=&quot;loginState === &#39;Authenticated&#39;&quot;&gt;&lt;/content-list&gt;<br>&lt;/template&gt;</pre><p>Now open <strong>./src/app.ts</strong> and subscribe to the login state just like we did it in the Login component. At this time we don’t need to <em>unsubscribe</em> because <em>app</em> is our main component — it will be attached right after Aurelia’s bootstrap process and will be detached on window close.</p><p>Update the <em>app.ts</em> file with the followings:</p><pre>import { Repository } from &quot;sn-client-js&quot;;<br>import { LoginState } from &quot;sn-client-js/dist/src/Authentication&quot;;<br>import { bindable, autoinject } from &quot;aurelia-framework&quot;;<br><br>@autoinject<br>export class App {<br>  constructor(private repository: Repository.BaseRepository) {  }<br><br>  @bindable<br>  loginState: LoginState<br><br>  attached(){<br>    this.repository.Authentication.State.subscribe(state=&gt;{<br>      this.loginState = state;<br>    });<br>  }<br>}</pre><blockquote><em>If you have unit tests enabled the one that tests the app component will now fail because we’ve modified the constructor and it will have a required argument. You can disable unit testing for now or fix the failed test in </em>./test/unit/app.spec.ts<em> file.</em></blockquote><h3>The view model</h3><p>The component list will have two bindable properties:</p><ul><li>currentContent: Content&lt;GenericContent&gt; will store the <em>current</em> tree level</li><li>children: Content&lt;GenericContent&gt;[] will store currentContent’s children. These will be displayed in the current view.</li></ul><p>And will have the following methods:</p><ul><li>currentContentChanged() is called by Aurelia when a new value is set to currentContent. We will load its children there.</li><li>navigate(content: Content&lt;GenericContent&gt;) will be called when clicking on a tree node (navigating a level below)</li><li>navigateUp() will set the current content to the current content’s parent and navigating a level up</li><li>attached() will initialize the component and sets the current content to the <em>Portal Root</em></li></ul><pre>import { bindable, autoinject } from &#39;aurelia-framework&#39;;<br>import { Content } from &#39;sn-client-js&#39;;<br>import { GenericContent } from &#39;sn-client-js/dist/src/ContentTypes&#39;;<br>import { BaseRepository } from &#39;sn-client-js/dist/src/Repository&#39;;<br><br>@autoinject<br>export class ContentList {<br>  constructor(private repository: BaseRepository) {  }<br><br>  attached(){<br>    this.repository.Load(2) // Get the PortalRoot by Id<br>    .subscribe(root=&gt;{<br>      this.currentContent = root;<br>    });<br>  }<br>  <br>  @bindable<br>  currentContent: Content&lt;GenericContent&gt;;<br><br>  @bindable<br>  children: Content&lt;GenericContent&gt;[] = []<br><br>  currentContentChanged(newValue) {<br>    this.currentContent.Children().subscribe(c=&gt;{<br>      this.children = c;<br>    })<br>  }<br><br>  navigate(content: Content){<br>    this.currentContent = content;<br>  }<br><br>  navigateUp(){<br>    this.repository.Load(this.currentContent.ParentPath)<br>      .subscribe(parent=&gt;{<br>        this.currentContent = parent;<br>      });<br>  }<br>}</pre><h3>The template</h3><p>The template will be quite simple, we will have a read-only input that will show the current Path and an unordered list with the children.</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;input readonly value.bind=&quot;currentContent.Path&quot; /&gt;<br>    &lt;ul&gt;<br>      &lt;li&gt;<br>        &lt;a click.delegate=&quot;navigateUp()&quot;&gt;[..]&lt;/a&gt;<br>      &lt;/li&gt;<br>      &lt;li repeat.for=&quot;child of children&quot;&gt;<br>        &lt;a click.delegate=&#39;navigate(child)&#39;&gt;${child.DisplayName || child.Name}&lt;/a&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/0*rYZxN9I0kIBNC8cj.gif" /></figure><h3>Next steps</h3><p>Now that you have an idea how to log in and load content you can find more examples about updating, deleting, querying at the <a href="https://github.com/SenseNet/sn-client-js">sn-client-js</a> readme or you can take a look at our <a href="https://github.com/SenseNet/sn-controls-aurelia">Aurelia control library</a>. And — as always — we are looking forward to your thoughts and feedback :).</p><p>Have feedback on this post? Let <a href="https://twitter.com/sensenet">@sensenet</a> know on Twitter.</p><p>Need help or found a bug? <a href="https://community.sensenet.com/contact">Contact us</a>.</p><p><em>Originally published at </em><a href="https://community.sensenet.com/blog/2018/01/10/starting-out-with-aurelia"><em>community.sensenet.com</em></a><em> on January 10, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=621f8717d6db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sensenet/getting-started-with-sensenet-ecm-using-aurelia-framework-621f8717d6db">Getting started with sensenet ECM using Aurelia Framework</a> was originally published in <a href="https://medium.com/sensenet">sensenet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Aurelia?]]></title>
            <link>https://medium.com/sensenet/why-aurelia-a81de706f4dd?source=rss-b8ec9e374f72------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81de706f4dd</guid>
            <category><![CDATA[sensenet]]></category>
            <category><![CDATA[headless-cms]]></category>
            <category><![CDATA[aurelia]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Lajos Gallay]]></dc:creator>
            <pubDate>Wed, 30 Aug 2017 00:00:00 GMT</pubDate>
            <atom:updated>2017-08-30T12:17:50.961Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*vkT5kzYBLJ1mvBLC8jh5Ug.png" /></figure><p>It’s a quite challengeing task to choose a front-end toolset nowadays, especially for a <a href="http://community.sensenet.com/blog/2017/05/31/product-goals">development platform</a>. Our concept with sensenet ECM 7+ is to support a wide range of front-end developers as far as possible with our <a href="https://github.com/SenseNet/sn-client-js">sn-client-js</a> package that can be integrated into almost every <a href="https://www.npmjs.com/">NPM</a> development pipeline. So far so good. But when it comes to build our new UI components we really had to choose between the modern libraries and frameworks. At this point we’ve decided to build on two of them for <a href="https://www.sensenet.com/for-customers/use-cases/single-page-application">SPA development</a>. I will explain why we’ve chosen <a href="http://aurelia.io/">Aurelia</a> besides <a href="https://facebook.github.io/react/">React</a>.</p><p>We have quite so much sensenet ECM specific client side features that can be made <em>framework independent</em> like user session management, content operations, querying. They work well in the core of our front-end library called <em>sn-client-js</em>. Some features — like templating, data binding or routing — are implemented in each and every framework and they are based on different concepts. We have just started to develop our component packages that depend on templating and data binding, that’s where and why we have to create the two new packages — <a href="https://github.com/SenseNet/sn-controls-aurelia">sn-controls-aurelia</a> and <a href="https://github.com/SenseNet/sn-controls-react">sn-controls-react</a>. They will contain <em>Aurelia / React</em> specific components and will use the core functionality from <em>sn-client-js</em>.</p><h4>View- and Field Controls — The next layer of our building blocks</h4><p>We have two major types of controls: Field controls and View controls. Field controls represent a specific field type (let’s say a simple short text) while view controls represent a content’s full view for a specific action (for example an <em>Edit</em> view of a user) and is built from FieldControl components based on the generated schema from <em>sn-client-js</em>. In the first round, we have to develop these controls as <em>Aurelia components</em>.</p><p>Aurelia has a clear concept of how a <a href="http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/creating-components/1">component</a> should look like. The view is separated from the view-model. View templates are written in a standard-based HTML extended with a very simple binding language and the view-model can be written in ES2015 or Typescript. If you take a look at the <a href="http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/creating-components/">example from the Aurelia hub</a> you can notice that there is only a little piece of framework-specific code in the template and nothing (!) in the view-model.</p><p>One of the cool things about Aurelia components is that you don’t need to dive deep in the framework. If you have a basic knowledge about HTML and Typescript you only have to learn how <em>data binding</em> works to create basic components. There are a lot of more complex possibilities however, like <a href="http://aurelia.io/hub.html#/doc/article/aurelia/templating/latest/templating-dynamic-ui-composition">dynamic composition</a>, <a href="http://aurelia.io/hub.html#/doc/article/aurelia/binding/latest/binding-value-converters">value converters</a> and <a href="http://aurelia.io/hub.html#/doc/article/aurelia/binding/latest/binding-computed-properties">computed properties</a>.</p><h4>Injecting dependencies</h4><p>As I mentioned, we will use dependencies from our other library called sn-client-js. Sometimes it can be difficult to use something universal <em>in a specific framework or library</em>, maybe you need additional decorators (therefore additional unnecessary layers) or sometimes this is even <em>nearly impossible</em> because of the incompatible principles. That’s not the case with Aurelia’s DI.</p><p>Aurelia Services — such as components — are plain Typescript classes. You only have to use the DI decorators <em>where</em> you want to use them. Ok, let’s take a look at the following snippet:</p><pre>import { Repository } from &#39;sn-client-js&#39;;<br>import { autoinject } from &#39;aurelia-framework&#39;;<br><br>@autoinject<br>export class HelloSnComponent{<br>    constructor(private readonly repository: Repository.SnRepository) {<br>        console.log(&#39;Hi there, your injected sensenet ECM Repository is:&#39;, this.repository);<br>    }<br>}</pre><p>All injected services will be singletons by default and that’s ok for our Repository object. If you want to configure your repository singleton with more specific options, you can do it from your <em>main.ts</em>’s configure:</p><pre>aurelia.container.registerSingleton(Repository.BaseRepository, () =&gt; {<br>    return new Repository.SnRepository(<br>      {<br>        RepositoryUrl: &#39;<a href="https://my-awesome-new-sensenet-site-with-aurelia-frontend.org/">https://my-awesome-new-sensenet-site-with-aurelia-frontend.org</a>&#39;<br>      });<br>  });</pre><p>Aurelia’s DI container is also an easy to use but powerful tool that don’t need much framework-specific knowledge.</p><h4>Packing together</h4><p>We want to distribute our controls as an NPM package and Aurelia also have a concept for <em>plugins</em>. This part isn’t documented well. To get the idea how a plugin works, we had to check the <a href="https://github.com/aurelia/skeleton-plugin">skeleton-plugin</a> package. The most important thing is the <em>configure</em> entry point that sets up the whole plugin.</p><h3>The core concepts that I agree with</h3><p>Creating components, using DI and creating an NPM package is not a big deal, it is doable with each and every framework that we’ve tested so I try to sum up how Aurelia differs from the others.</p><h4>“A framework should get out of my way”</h4><p>One of the key part is its unobtrusiveness and it has been taken very seriously. There are some basic conventions (e.g. template syntax, element naming or component lifecycle event naming) and a minimal configuration but most of the time it just helps you get the <em>job</em> done. It lets you focus on your application (or in our case, a component package) instead of the framework.</p><h4>Quality and performance</h4><p>Aurelia follows <a href="http://semver.org/">Semver</a> and there were no breaking changes in the Core APIs since the first stable release. I’ve started to use Aurelia in the fall of 2016 and there were no upgrade issues since then. I also didn’t encounter any performance bottlenecks, even for complex controls and pages.</p><h4>Loosely coupled goodies</h4><p>However we spoke of Aurelia as a <em>framework</em>, it is defined as a “<em>collection of Modern JavaScript modules</em>”. Each <em>module</em> (like the binding, dependency injection or templating) has its own NPM package as well but you are not forced to use all of them. That means you don’t have to use e.g. the <em>aurelia-http-client</em> module if you have your own module for handling HTTP requests — and that’s the case for sn-client-js. We used the router, the validation plugin and the testing packages. Aurelia also has a <a href="http://blog.aurelia.io/2016/10/11/introducing-the-aurelia-vs-code-plugin/">VS Code plugin</a>, a <a href="https://chrome.google.com/webstore/detail/aurelia-inspector/ofemgdknaajmpeoblfdjkenbpcfbdefg?hl=en">Chrome Inspector extension</a> and a <a href="https://github.com/aurelia/cli">command line tool</a>.</p><h3>Room for improvement</h3><p>However I really enjoy working with Aurelia, there are a few pain points. The first is that the community is much smaller when comparing to for example React or Angular2+ and grows slower than vue.js’s community.</p><p>There are other things missing, fortunately the Aurelia team has also recognized them and mentioned them in their <a href="http://blog.aurelia.io/2017/01/02/aurelia-2017-resolutions/">2017’s new year resolution</a>. The first is server side rendering which is completely missing feature at the moment. The second is the lack of a suitable ready-to-use component set. There are <em>bridges</em> to existing component sets like <a href="https://github.com/aurelia-ui-toolkits/aurelia-kendoui-bridge">Kendo UI</a> (that we can’t use in an open source project due licensing incompatibility) or <a href="https://github.com/aurelia-ui-toolkits/aurelia-materialize-bridge">Materialize</a> (we are using it at the moment, but we are not satisfied with it). <a href="http://blog.aurelia.io/2016/11/04/introducing-aurelia-ux/">Aurelia UX</a> has been announced nearly a year ago but it seems that it is far from complete at the moment.</p><p>Have feedback on this post? Let <a href="https://twitter.com/sensenet">@sensenet</a> know on Twitter.</p><p>Need help or found a bug? <a href="http://community.sensenet.com/contact">Contact us</a>.</p><p><em>Originally published at </em><a href="http://community.sensenet.com/blog/2017/08/30/why-aurelia"><em>community.sensenet.com</em></a><em> on August 30, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81de706f4dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sensenet/why-aurelia-a81de706f4dd">Why Aurelia?</a> was originally published in <a href="https://medium.com/sensenet">sensenet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>