Skip to content

Commit

Permalink
update README/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Sep 10, 2024
1 parent 3c0e176 commit 6e88b86
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Lowclass is a lib that includes the following inheritance tools:
`multiple()`. For example:

```js
import {Mixin} from 'lowclass'
import {Mixin} from 'lowclass/dist/Mixin.js'

// define a few "class-factory mixins":
const Walker = Mixin(Base => {
Expand Down Expand Up @@ -152,7 +152,7 @@ Lowclass is a lib that includes the following inheritance tools:
- A `Class()` tool for creating classes with public, protected, and private members. For example:

```js
import Class from 'lowclass'
import Class from 'lowclass/dist/Class.js'
import Something from 'somewhere'

export default Class('Thing').extends(Something, ({Protected, Private}) => ({
Expand Down Expand Up @@ -263,13 +263,12 @@ console.log(instance._protectedProperty) // "yoohoo"
The good news is, you can use lowclass to add Protected and Private
functionality to your existing classes!

Just wrap your class with lowclass to gain Protected or Private functionality:
Just wrap your class with Class to gain Protected or Private functionality:

```js
import protect from 'lowclass'
// or const protect = require('lowclass')
import {Class} from 'lowclass/dist/Class.js'

const Thing = protect(({Protected}) => {
const Thing = Class(({Protected}) => {
return class Thing {
constructor() {
// make the property truly protected
Expand All @@ -286,7 +285,7 @@ const Thing = protect(({Protected}) => {
We can make it a little cleaner:

```js
const Thing = protect(
const Thing = Class(
({Protected}) =>
class {
constructor() {
Expand All @@ -303,7 +302,7 @@ const Thing = protect(
If we were exporting this from a module, we could write it like this:

```js
export default protect(
export default Class(
({Protected}) =>
class Thing {
constructor() {
Expand All @@ -321,7 +320,7 @@ You might still be making ES5-style classes using `function() {}` instead of
`class`. In this case wrapping it would look like this:

```js
const Thing = protect(({Protected}) => {
const Thing = Class(({Protected}) => {
function Thing() {
Protected(this).protectedProperty = 'yoohoo'
}
Expand Down Expand Up @@ -365,7 +364,7 @@ class Something extends Thing {
We will wrap it with lowclass too, so that it can inherit the protected member:

```js
const Something = protect(
const Something = Class(
({Protected}) =>
class extends Thing {
otherMethod() {
Expand All @@ -379,7 +378,7 @@ const Something = protect(
If you are writing ES5-style classes, it will look something like this:

```js
const Something = protect(({Protected}) => {
const Something = Class(({Protected}) => {
function Something() {
Thing.call(this)
}
Expand Down Expand Up @@ -419,7 +418,7 @@ Here's an example that shows the concept, but this time we will define the
classes directly with lowclass, instead of wrapping a class:

```js
import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

const Thing = Class(({Private}) => ({
constructor() {
Expand Down Expand Up @@ -457,8 +456,7 @@ Let's illustrate this with an example, then we'll explain afterwords how it
works:

```js
const Class = require('lowclass')
// or import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

const Thing = Class(({Private}) => ({
constructor() {
Expand Down Expand Up @@ -603,7 +601,7 @@ classes interact with eachother.
// show how to do something similar to "friend" in C++ or "package protected"
// in Java.

import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

let CounterProtected

Expand Down Expand Up @@ -854,7 +852,7 @@ We can also stick lowclass onto any constructor, and use it just like the
previous example:

```js
import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

Array.subclass = Class

Expand Down
2 changes: 1 addition & 1 deletion dist/WIP-test-lowclass-types.ts.off
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

const Animal = Class('Animal', {
sound: '',
Expand Down
2 changes: 1 addition & 1 deletion src/WIP-test-lowclass-types.ts.off
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Class from 'lowclass'
import {Class} from 'lowclass/dist/Class.js'

const Animal = Class('Animal', {
sound: '',
Expand Down
2 changes: 1 addition & 1 deletion src/tests/readme-examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const test = it

describe('README examples', () => {
test('use a real protected member instead of the underscore convention, ES2015 classes', () => {
// an alias, which semantically more meaningful when wrapping a native
// an alias, which can be semantically more meaningful when wrapping a native
// `class` that already contains the "class" keyword.
const protect = Class

Expand Down

0 comments on commit 6e88b86

Please sign in to comment.