react-cursor

Immutable state for React.js

  • 所有者: dustingetz/react-cursor
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

react-cursor

Immutable state for React.js

react-cursor hello-world in a fiddle

live demo

What is react-cursor

Cursors are a tool for working with recursive or deeply nested data, immutably. react-cursor is a javascript port of an abstraction that I first saw in ClojureScript. This implementation is decoupled from any rendering library and is very small.

Cursors are useful in UI programming, because UIs are tree shaped and naturally have tree-shaped state. Cursors let your app hold all its state in one place at the root of the UI tree; thus the root is stateful, and all downtree views are stateless.

Project Maturity

master is stable, there is a full test suite.

API

Cursor interface has three methods: value, swap and refine.

  • cur.value() return the value in the cursor at some path.
  • cur.refine(path, ...paths) return a cursor nested inside another cursor
  • cur.swap(f) apply f to the value in the cursor value and puts returned value into the backing store

For frequently used swap functions, see the bundled update-in dependency: see here. Cursor instances have optional syntax sugar for the swap fns provided by update-in; see CursorOperations.js

FAQ

  • Cursors have value semantics, don't mutate values that come out of a cursor
  • Equal cursors are === for easy and efficient optimized rendering (see hello world jsfiddle for example)
  • You should read the source! The core cursor abstraction is 15 lines of code
  • There is an undocumented alternate implementation, RefCursor, which has reference semantics, this is only useful for working with legacy mutable code

License

react-cursor is governed under the MIT License.

Attributions

react-cursor was built by Daniel Miladinov and Dustin Getz.

主要指標

概覽
名稱與所有者dustingetz/react-cursor
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證
所有者活动
創建於2014-07-14 00:55:05
推送於2017-01-27 19:51:23
最后一次提交2017-01-27 14:51:22
發布數4
最新版本名稱v1.2.1 (發布於 )
第一版名稱0.9.2 (發布於 2015-02-24 08:10:13)
用户参与
星數1k
關注者數19
派生數50
提交數266
已啟用問題?
問題數60
打開的問題數9
拉請求數27
打開的拉請求數1
關閉的拉請求數10
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?