Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Atom/Lens-only version to focal-atom #72

Merged
merged 32 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e14411d
Move focal-state into separate packages
oleksiilevzhynskyi Jun 15, 2020
d8cdbbc
Use tsconfig «references» feature to build local dependencies
oleksiilevzhynskyi Jun 15, 2020
d97afac
Add «dev» build and allow to run «dev» and «clean» from root packages
oleksiilevzhynskyi Jun 15, 2020
22ac5ae
Use focal@0.8.1 in examples
oleksiilevzhynskyi Jun 15, 2020
479965d
«clean» before build when called from root
oleksiilevzhynskyi Jun 15, 2020
e35a2cd
rename focal-state to focal-atom
oleksiilevzhynskyi Jun 16, 2020
2a46cf7
use release script to relase focal and focal-state at once
oleksiilevzhynskyi Jun 16, 2020
7c613e5
Move contributors to AUTHORS file
oleksiilevzhynskyi Jun 16, 2020
329877f
Better release script
oleksiilevzhynskyi Jun 16, 2020
f6566d5
Update release script
oleksiilevzhynskyi Jun 17, 2020
d99b00c
Update Readme to mention @grammarly/focal-atom
oleksiilevzhynskyi Jun 17, 2020
e0739a6
Move structEq to focal-atom and delete focal-utils
oleksiilevzhynskyi Jul 16, 2020
9f2ac85
Merge remote-tracking branch 'origin/master' into feature-focal-state-2
oleksiilevzhynskyi Sep 18, 2020
c0cc731
v0.0.0
oleksiilevzhynskyi Sep 21, 2020
43c8bfe
Merge remote-tracking branch 'origin/master' into feature-focal-state-2
oleksiilevzhynskyi Apr 2, 2021
c8e19a8
don’t build focal on post-install
oleksiilevzhynskyi Apr 4, 2021
c225c96
use bash script to do packaging
oleksiilevzhynskyi Apr 4, 2021
e6e98d3
fix typos in release Readme workflow
oleksiilevzhynskyi Apr 4, 2021
d7fd82c
Merge remote-tracking branch 'origin/master' into feature-focal-state-2
oleksiilevzhynskyi Apr 4, 2021
23a373f
use prepack and postpack to copy License and Readme
oleksiilevzhynskyi Apr 4, 2021
7e6b372
fix yarn.lock
oleksiilevzhynskyi Apr 4, 2021
e941d4b
move AUTHORS to package.json
oleksiilevzhynskyi Apr 6, 2021
8c3e3b7
remove pack.sh as it no longer needed
oleksiilevzhynskyi Apr 6, 2021
afe3f6a
sync focal and focal-atom versions
oleksiilevzhynskyi Apr 6, 2021
6c7998d
update release scripts
oleksiilevzhynskyi Apr 6, 2021
0e4c3f1
use eslint in focal-atom
oleksiilevzhynskyi Apr 6, 2021
c51daa2
Merge remote-tracking branch 'origin/master' into feature-focal-state-2
oleksiilevzhynskyi Sep 9, 2022
d4a174f
Fixes after merge with latest master
oleksiilevzhynskyi Sep 9, 2022
0e5b0e6
Update outdated typescript-eslint plugins
oleksiilevzhynskyi Sep 9, 2022
773e638
Expose `structEq` from «@grammarly/focal» to avoid breaking changes
oleksiilevzhynskyi Sep 11, 2022
754fd05
Move focal-atom to dependencies of focal. This should avoid breaking …
oleksiilevzhynskyi Feb 26, 2023
70d575e
Derussification
blacktaxi Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## Release

1. Create pull-request for relese "Release vX.X.X"
1. Create a pull request for release "Release vX.X.X"
2. Run in root `yarn bump-release X.X.X`
3. yarn bump-release will bump focal version, update deps in private packages and create a commit
3. run `yarn bump-release` to bump focal and focal-atom version, update dependancies in private packages and create a commit
4. Merge and manually create [GitHub Release](https://github.com/grammarly/focal/releases)
5. On release "publish" GitHub Actions will trigger build and attach tarball to "Release". For details see `release.yml`
5. On release, "publish" GitHub Actions will trigger build and attach tarball to "Release". For details, see `release.yml`

## Tests

For each push into pull_reusets CI runs tests. Check `tests.yml` for details.
For each push into pull_request, CI runs tests. Check `tests.yml` for details.
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ jobs:
id: branch_name
run: |
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-output name=TARBALL::grammarly-focal-${GITHUB_REF#refs/tags/}.tgz
echo ::set-output name=TARBALL_FOCAL::grammarly-focal-${GITHUB_REF#refs/tags/}.tgz
echo ::set-output name=TARBALL_FOCAL_ATOM::grammarly-focal-atom-${GITHUB_REF#refs/tags/}.tgz
- name: Checkout code
uses: actions/checkout@v2
- run: yarn install
- run: yarn build
- run: yarn test
- run: yarn package
- name: Upload binaries to release
- name: Upload @grammarly/focal binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./packages/focal/${{ steps.branch_name.outputs.TARBALL }}
asset_name: ${{ steps.branch_name.outputs.TARBALL }}
file: ./packages/focal/${{ steps.branch_name.outputs.TARBALL_FOCAL }}
asset_name: ${{ steps.branch_name.outputs.TARBALL_FOCAL }}
tag: ${{ github.ref }}
- name: Upload @grammarly/focal-atom binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./packages/focal-atom/${{ steps.branch_name.outputs.TARBALL_FOCAL_ATOM }}
asset_name: ${{ steps.branch_name.outputs.TARBALL_FOCAL_ATOM }}
tag: ${{ github.ref }}
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Type safe, expressive and composable state management for [React](https://facebo
- Use [lenses](https://en.wikibooks.org/wiki/Haskell/Lenses_and_functional_references) to decompose the application state into smaller parts, so you can isolate UI components in a clean way and manipulate application state effortlessly.
- Write less code that is easier to understand.

# Packages

`@grammarly/focal` - Type safe, expressive and composable state management for [React](https://facebook.github.io/react/) applications.
`@grammarly/focal-atom` - Type safe, expressive and composable state management for any application.

# Example

Here's a typical example of a 'counter' UI component and how it fits within the whole application:
Expand Down Expand Up @@ -75,13 +80,18 @@ There's also a more elaborate version of [this example](packages/examples/all/sr
# Installation

```bash
yarn add @grammarly/focal
yarn add @grammarly/focal-atom @grammarly/focal
# or
yarn add @grammarly/focal-atom

```

or

```bash
npm install --save @grammarly/focal
npm install --save @grammarly/focal-atom @grammarly/focal
# or
npm install --save @grammarly/focal-atom
```

It is important to satisfy the RxJS peer dependency (required for `instanceof Observable` tests to work correctly).
Expand All @@ -100,7 +110,7 @@ The example above might be a bit too overwhelming. Let's go over the main concep
In Focal, state is stored in `Atom<T>`s. `Atom<T>` is a data cell that holds a single immutable value, which you can read and write to:

```typescript
import { Atom } from '@grammarly/focal'
import { Atom } from '@grammarly/focal-atom'

// create an Atom<number> with initial value of 0
const count = Atom.create(0)
Expand All @@ -125,7 +135,7 @@ console.log(count.get())
You can also track (get notified of) changes that happen to an `Atom<T>`'s value. In this sense, an `Atom<T>` can be thought of as a _reactive variable_:

```typescript
import { Atom } from '@grammarly/focal'
import { Atom } from '@grammarly/focal-atom'

const count = Atom.create(0)

Expand Down Expand Up @@ -287,7 +297,7 @@ interface Lens<TSource, T> {
And an example usage:

```typescript
import { Lens } from '@grammarly/focal'
import { Lens } from '@grammarly/focal-atom'

// an object that we want to operate on
const obj = {
Expand Down Expand Up @@ -400,7 +410,7 @@ We can accomplish this by combining atoms with lenses, making _lensed atoms_.
A lensed atom is just an `Atom<T>`, in sense that on the outside it looks and behaves just like another atom. The difference is in how it is created: a lensed atom operates on a part of some other atom's state. This means that if you `.set` or `.modify` a lensed atom's value, the part of the source atom's value at which this lensed atom's lens is focused will also change. For example:

```typescript
import { Atom, Lens } from '@grammarly/focal'
import { Atom, Lens } from '@grammarly/focal-atom'

// create an atom to hold our object
const obj = Atom.create({
Expand Down
36 changes: 22 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
{
"private": true,
"name": "focal",
"version": "0.0.0",
"workspaces": [
"packages/focal-atom",
"packages/focal",
"packages/test",
"packages/examples/*"
],
"nohoist": [
"tslint-eslint-rules"
],
"scripts": {
"build": "yarn workspace @grammarly/focal build",
"lint": "yarn lint:focal && yarn lint:test && yarn lint:todomvc && yarn lint:examples",
"build": "yarn clean && yarn workspace @grammarly/focal build",
"dev": "yarn workspace @grammarly/focal dev",
"clean": "yarn workspace @grammarly/focal-atom clean && yarn workspace @grammarly/focal clean",
"docs": "yarn workspace @grammarly/focal-atom docs && yarn workspace @grammarly/focal docs",
"lint": "yarn lint:focal-atom && yarn lint:focal && yarn lint:test && yarn lint:todomvc && yarn lint:examples",
"lint:focal": "yarn workspace @grammarly/focal lint",
"lint:focal-atom": "yarn workspace @grammarly/focal-atom lint",
"lint:test": "yarn workspace focal-manual-tests lint",
"lint:todomvc": "yarn workspace focal-todomvc lint",
"lint:examples": "yarn workspace focal-examples lint",
"package": "yarn workspace @grammarly/focal pack",
"test": "yarn workspace @grammarly/focal test && yarn workspace focal-todomvc build && yarn workspace focal-examples build && yarn workspace focal-manual-tests build",
"postinstall": "yarn build",
"bump-version": "sh ./scripts/release.sh"
"test": "yarn workspace @grammarly/focal-atom test && yarn workspace @grammarly/focal test && yarn workspace focal-todomvc build && yarn workspace focal-examples build && yarn workspace focal-manual-tests build",
"package": "yarn workspace @grammarly/focal-atom pack && yarn workspace @grammarly/focal pack",
"bump-version": "sh ./scripts/bump-version.sh"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/eslint-plugin-tslint": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"eslint": "^7.18.0",
"eslint-plugin-jsdoc": "^31.0.8",
"eslint-plugin-react": "^7.22.0",
"typescript": "^4.7.4"
},
"workspaces": [
"packages/focal",
"packages/test",
"packages/examples/*"
],
"resolutions": {
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/focal-atom/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module",
"tsconfigRootDir": __dirname,
}
}
1 change: 1 addition & 0 deletions packages/focal-atom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
16 changes: 16 additions & 0 deletions packages/focal-atom/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: [
'js',
'ts',
'tsx',
],
testEnvironment: 'jest-environment-jsdom',
testMatch: [
'**/*.test.ts?(x)',
],
transform: {
'.(ts|tsx)': 'ts-jest',
},
preset: 'ts-jest'
}
107 changes: 107 additions & 0 deletions packages/focal-atom/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"name": "@grammarly/focal-atom",
"version": "0.9.0",
"description": "FRP Atom: observables, immutable data and lenses",
"main": "dist/_cjs/src/index.js",
"module": "dist/_esm5/src/index.js",
"es2015": "dist/_esm2015/src/index.js",
"types": "dist/_cjs/src/index.d.ts",
"sideEffects": [
"./dist/_cjs/src/lens/json.js",
"./dist/_esm5/src/lens/json.js",
"./dist/_esm2015/src/lens/json.js"
],
"files": [
"dist/_cjs/src/",
"dist/_esm5/src/",
"dist/_esm2015/src/"
],
"scripts": {
"docs": "rm -rf ./docs && typedoc --out docs --theme minimal --ignoreCompilerErrors --tsconfig tsconfig.json",
"clean": "rm -rf ./dist",
"dev": "tsc -b -w tsconfig.build.cjs.json",
"build:cjs": "tsc -b tsconfig.build.cjs.json",
"build:es5": "tsc -b tsconfig.build.es5.json",
"build:es2015": "tsc -b tsconfig.build.es2015.json",
"build": "npm run clean && yarn build:cjs && yarn build:es5 && yarn build:es2015 && npm run lint",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint './src/**/*.ts*' 'test/**/*.ts*' && tsc --noemit",
"prepack": "cp ../../README.md ./ && cp ../../LICENSE ./",
"postpack": "rm README.md && rm LICENSE"

},
"author": "Sergey Yavnyi <sergey.yavnyi@grammarly.com>",
"contributors": [
{
"name": "Sergey Yavnyi",
"email": "sergey.yavnyi@grammarly.com"
},
{
"name": "Valentyn Gaidylo",
"email": "valentyn.gaidylo@grammarly.com"
},
{
"name": "Igor Kononuchenko",
"email": "igor.kononuchenko@grammarly.com"
},
{
"name": "Alisa Mansurova",
"email": "alisa.mansurova@grammarly.com"
},
{
"name": "Eugene Chechuryn",
"email": "eugene.chechuryn@grammarly.com"
},
{
"name": "Yaroslav Voloshchuk",
"email": "yaroslav.voloshchuk@grammarly.com"
},
{
"name": "Sergey Rudenko",
"email": "sergey.rudenko@grammarly.com"
},
{
"name": "Gregory Shehet",
"email": "gregory.shehet@grammarly.com"
},
{
"name": "Anton Verinov",
"email": "anton@verinov.com"
},
{
"name": "Oleksii Levzhynskyi",
"email": "oleksii.levzhynskyi@grammarly.com"
},
{
"name": "Vladyslav Bozhko",
"email": "vladyslav.bozhko@grammarly.com"
}
],
"keywords": [
"frp",
"rx",
"rxjs",
"reactive",
"react",
"reactjs",
"lens"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/grammarly/focal.git"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "^24.0.20",
"@types/node": "^18.0.0",
"jest": "^28.1.1",
"rxjs": "6.3.3",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
},
"peerDependencies": {
"rxjs": ">= 6.3.3 < 7.0.0-0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Lens, Prism, PropExpr } from './../lens'
import { structEq, Option } from './../utils'
import { Option } from './../utils'
import { structEq } from './../equals'

import { Observable, Subscriber, Subscription, BehaviorSubject, combineLatest } from 'rxjs'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function type(val: any) {
* var b = {}; b.v = b
* equals(a, b); //=> true
*/
export function equals(a: any, b: any, stackA: any[] = [], stackB: any[] = []) {
export function structEq(a: any, b: any, stackA: any[] = [], stackB: any[] = []) {
if (identical(a, b)) return true
if (type(a) !== type(b)) return false
if (a == null || b == null) return false
Expand Down Expand Up @@ -244,7 +244,7 @@ export function equals(a: any, b: any, stackA: any[] = [], stackB: any[] = []) {

case 'Map':
case 'Set':
if (!equals(arrayFromIterator(a.entries()), arrayFromIterator(b.entries()), stackA, stackB))
if (!structEq(arrayFromIterator(a.entries()), arrayFromIterator(b.entries()), stackA, stackB))
return false

break
Expand Down Expand Up @@ -286,7 +286,7 @@ export function equals(a: any, b: any, stackA: any[] = [], stackB: any[] = []) {
while (idx >= 0) {
const key = keysA[idx]

if (!(has(key, b) && equals(b[key], a[key], stackA, stackB)))
if (!(has(key, b) && structEq(b[key], a[key], stackA, stackB)))
return false

idx -= 1
Expand Down
4 changes: 4 additions & 0 deletions packages/focal-atom/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { Lens, Prism, Optic } from './lens/index'
export { Atom, ReadOnlyAtom } from './atom/index'
export { Option } from './utils'
export { structEq } from './equals'
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import {
structEq,
setKey,
conservatively,
findIndex,
Expand All @@ -14,6 +13,10 @@ import {
warning
} from './../utils'

import {
structEq
} from './../equals'

import { Lens, Prism } from './base'

export type PropExpr<O, P> = (x: O) => P
Expand Down
Loading