aleclarson / react-galaxy Goto Github PK
View Code? Open in Web Editor NEWReactive rendering via immutable copies (powered by immer 👉https://goo.gl/t7gJPr), and more! -- Guide/documentation 👉https://react-galaxy.github.io
License: MIT License
Reactive rendering via immutable copies (powered by immer 👉https://goo.gl/t7gJPr), and more! -- Guide/documentation 👉https://react-galaxy.github.io
License: MIT License
Currently, using derive
with an array is inefficient if you want a mapped/sorted copy of the array, because previously mapped/sorted values must be reprocessed.
Adding map
and sort
functions would allow us to make the necessary optimizations:
import {track, revise, derive, map, sort} from 'react-galaxy'
let arr = track([ 5, 10 ])
let increment = (value: number) => value + 1
let descending = (a: number, b: number) => a > b ? -1 : 1
// The inefficient way.
let slowMapped = derive(arr, (arr) => arr.map(increment))
let slowSorted = derive(arr, (arr) => arr.slice().sort(descending))
// The proposed way.
let fastMapped = map(arr, increment)
let fastSorted = sort(arr, descending)
revise(arr, draft => {
draft.push(0)
})
fastMapped.value // => [ 6, 11, 1 ]
fastSorted.value // => [ 10, 5, 0 ]
The slowMapped
and slowSorted
values are reconstructed from an empty array whenever arr
is revised.
The fastMapped
and fastSorted
values are patched based on how arr
is changed between revisions.
Other array-focused functions like filter
, binarySort
, and mapFilter
could be added too.
Export a new function that is like watch(base, patchListener)
, but includes changes to nested reactive objects.
This would be a "heavier" function, because patches to nested objects need to be cloned so their path
property is relative to the base
object.
Let selectors return the nothing
symbol (created by Immer, re-exported by Galaxy) to use the last selected value.
Selectors used by Read
components interpret nothing
to mean "skip re-rendering" (as long as all selectors return nothing
or don't change). If the Read
component has not rendered before, it will render null
until all selectors
return a non-nothing
value.
This is useful when a selector wants to "bail" if some required value is missing, and skipping updates is preferred to throwing an error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.